mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-06 16:57:04 +08:00
Prep for 5.0.0 release
This commit is contained in:
parent
a951d2b0af
commit
a67022e31e
@ -1,319 +0,0 @@
|
||||
#include <chaiscript/utility/utility.hpp>
|
||||
|
||||
|
||||
using namespace chaiscript;
|
||||
|
||||
|
||||
template<typename T>
|
||||
void use(T){}
|
||||
|
||||
template<typename To>
|
||||
bool run_test_type_conversion(const Boxed_Value &bv, bool expectedpass)
|
||||
{
|
||||
try {
|
||||
To ret = chaiscript::boxed_cast<To>(bv);
|
||||
use(ret);
|
||||
} catch (const chaiscript::exception::bad_boxed_cast &/*e*/) {
|
||||
if (expectedpass) {
|
||||
// std::cerr << "Failure in run_test_type_conversion: " << e.what() << std::endl;
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "Unexpected standard exception when attempting cast_conversion: " << e.what() << std::endl;
|
||||
return false;
|
||||
} catch (...) {
|
||||
std::cerr << "Unexpected unknown exception when attempting cast_conversion." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (expectedpass)
|
||||
{
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename To>
|
||||
bool test_type_conversion(const Boxed_Value &bv, bool expectedpass)
|
||||
{
|
||||
bool ret = run_test_type_conversion<To>(bv, expectedpass);
|
||||
|
||||
if (!ret)
|
||||
{
|
||||
std::cerr << "Error with type conversion test. From: "
|
||||
<< (bv.is_const()?(std::string("const ")):(std::string())) << bv.get_type_info().name()
|
||||
<< " To: "
|
||||
<< (boost::is_const<To>::value?(std::string("const ")):(std::string())) << typeid(To).name()
|
||||
<< " test was expected to " << ((expectedpass)?(std::string("succeed")):(std::string("fail"))) << " but did not" << std::endl;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
bool do_test(const Boxed_Value &bv, bool T, bool ConstT, bool TRef, bool ConstTRef, bool TPtr, bool ConstTPtr, bool TPtrConst,
|
||||
bool ConstTPtrConst, bool SharedPtrT, bool SharedConstPtrT,
|
||||
bool ConstSharedPtrT, bool ConstSharedConstPtrT, bool ConstSharedPtrTRef, bool ConstSharedPtrTConstRef,
|
||||
bool BoostRef, bool BoostConstRef, bool ConstBoostRef, bool ConstBoostConstRef,
|
||||
bool ConstBoostRefRef, bool ConstBoostConstRefRef, bool Number,
|
||||
bool ConstNumber, bool ConstNumberRef, bool TPtrConstRef, bool ConstTPtrConstRef)
|
||||
{
|
||||
bool passed = true;
|
||||
passed &= test_type_conversion<Type>(bv, T);
|
||||
passed &= test_type_conversion<const Type>(bv, ConstT);
|
||||
passed &= test_type_conversion<Type &>(bv, TRef);
|
||||
passed &= test_type_conversion<const Type &>(bv, ConstTRef);
|
||||
passed &= test_type_conversion<Type *>(bv, TPtr);
|
||||
passed &= test_type_conversion<const Type *>(bv, ConstTPtr);
|
||||
passed &= test_type_conversion<Type * const>(bv, TPtrConst);
|
||||
passed &= test_type_conversion<const Type * const>(bv, ConstTPtrConst);
|
||||
passed &= test_type_conversion<boost::shared_ptr<Type> >(bv, SharedPtrT);
|
||||
passed &= test_type_conversion<boost::shared_ptr<const Type> >(bv, SharedConstPtrT);
|
||||
passed &= test_type_conversion<boost::shared_ptr<Type> &>(bv, false);
|
||||
passed &= test_type_conversion<boost::shared_ptr<const Type> &>(bv, false);
|
||||
passed &= test_type_conversion<const boost::shared_ptr<Type> >(bv, ConstSharedPtrT);
|
||||
passed &= test_type_conversion<const boost::shared_ptr<const Type> >(bv, ConstSharedConstPtrT);
|
||||
passed &= test_type_conversion<const boost::shared_ptr<Type> &>(bv, ConstSharedPtrTRef);
|
||||
passed &= test_type_conversion<const boost::shared_ptr<const Type> &>(bv, ConstSharedPtrTConstRef);
|
||||
passed &= test_type_conversion<boost::reference_wrapper<Type> >(bv, BoostRef);
|
||||
passed &= test_type_conversion<boost::reference_wrapper<const Type> >(bv, BoostConstRef);
|
||||
passed &= test_type_conversion<boost::reference_wrapper<Type> &>(bv, false);
|
||||
passed &= test_type_conversion<boost::reference_wrapper<const Type> &>(bv, false);
|
||||
passed &= test_type_conversion<const boost::reference_wrapper<Type> >(bv, ConstBoostRef);
|
||||
passed &= test_type_conversion<const boost::reference_wrapper<const Type> >(bv, ConstBoostConstRef);
|
||||
passed &= test_type_conversion<const boost::reference_wrapper<Type> &>(bv, ConstBoostRefRef);
|
||||
passed &= test_type_conversion<const boost::reference_wrapper<const Type> &>(bv, ConstBoostConstRefRef);
|
||||
passed &= test_type_conversion<Boxed_Number>(bv, Number);
|
||||
passed &= test_type_conversion<const Boxed_Number>(bv, ConstNumber);
|
||||
passed &= test_type_conversion<Boxed_Number &>(bv, false);
|
||||
passed &= test_type_conversion<const Boxed_Number &>(bv, ConstNumberRef);
|
||||
passed &= test_type_conversion<Boxed_Number *>(bv, false);
|
||||
passed &= test_type_conversion<const Boxed_Number *>(bv, false);
|
||||
passed &= test_type_conversion<Boxed_Number * const>(bv, false);
|
||||
passed &= test_type_conversion<const Boxed_Number *const>(bv, false);
|
||||
passed &= test_type_conversion<Type *&>(bv, false);
|
||||
passed &= test_type_conversion<const Type *&>(bv, false);
|
||||
passed &= test_type_conversion<Type * const&>(bv, TPtrConstRef);
|
||||
passed &= test_type_conversion<const Type * const&>(bv, ConstTPtrConstRef);
|
||||
passed &= test_type_conversion<Boxed_Value>(bv, true);
|
||||
passed &= test_type_conversion<const Boxed_Value>(bv, true);
|
||||
passed &= test_type_conversion<const Boxed_Value &>(bv, true);
|
||||
|
||||
return passed;
|
||||
}
|
||||
|
||||
/** Tests intended for built int types **/
|
||||
template<typename T>
|
||||
bool built_in_type_test(const T &initial, bool ispod)
|
||||
{
|
||||
bool passed = true;
|
||||
|
||||
/** value tests **/
|
||||
T i = T(initial);
|
||||
passed &= do_test<T>(var(i), true, true, true, true, true,
|
||||
true, true, true, true, true,
|
||||
true, true, true, true, true,
|
||||
true, true, true, true, true,
|
||||
ispod && true, ispod && true, ispod && true, true, true);
|
||||
|
||||
passed &= do_test<T>(const_var(i), true, true, false, true, false,
|
||||
true, false, true, false, true,
|
||||
false, true, false, true, false,
|
||||
true, false, true, false, true,
|
||||
ispod && true, ispod && true, ispod && true, false, true);
|
||||
|
||||
passed &= do_test<T>(var(&i), true, true, true, true, true,
|
||||
true, true, true, false, false,
|
||||
false, false, false, false, true,
|
||||
true, true, true, true, true,
|
||||
ispod && true, ispod && true, ispod && true, true, true);
|
||||
|
||||
passed &= do_test<T>(const_var(&i), true, true, false, true, false,
|
||||
true, false, true, false, false,
|
||||
false, false, false, false, false,
|
||||
true, false, true, false, true,
|
||||
ispod && true, ispod && true, ispod && true, ispod && false, true);
|
||||
|
||||
passed &= do_test<T>(var(boost::ref(i)), true, true, true, true, true,
|
||||
true, true, true, false, false,
|
||||
false, false, false, false, true,
|
||||
true, true, true, true, true,
|
||||
ispod && true, ispod && true, ispod && true, true, true);
|
||||
|
||||
passed &= do_test<T>(var(boost::cref(i)), true, true, false, true, false,
|
||||
true, false, true, false, false,
|
||||
false, false, false, false, false,
|
||||
true, false, true, false, true,
|
||||
ispod && true, ispod && true, ispod && true, false, true);
|
||||
|
||||
/** Const Reference Variable tests */
|
||||
|
||||
// This reference will be copied on input, which is expected
|
||||
const T &ir = i;
|
||||
|
||||
passed &= do_test<T>(var(i), true, true, true, true, true,
|
||||
true, true, true, true, true,
|
||||
true, true, true, true, true,
|
||||
true, true, true, true, true,
|
||||
ispod && true, ispod && true, ispod && true, true, true);
|
||||
|
||||
// But a pointer or reference to it should be necessarily const
|
||||
passed &= do_test<T>(var(&ir), true, true, false, true, false,
|
||||
true, false, true, false, false,
|
||||
false, false, false, false, false,
|
||||
true, false, true, false, true,
|
||||
ispod && true, ispod && true, ispod && true, false, true);
|
||||
|
||||
passed &= do_test<T>(var(boost::ref(ir)), true, true, false, true, false,
|
||||
true, false, true, false, false,
|
||||
false, false, false, false, false,
|
||||
true, false, true, false, true,
|
||||
ispod && true, ispod && true, ispod && true, false, true);
|
||||
|
||||
// Make sure const of const works too
|
||||
passed &= do_test<T>(const_var(&ir), true, true, false, true, false,
|
||||
true, false, true, false, false,
|
||||
false, false, false, false, false,
|
||||
true, false, true, false, true,
|
||||
ispod && true, ispod && true, ispod && true, false, true);
|
||||
|
||||
passed &= do_test<T>(const_var(boost::ref(ir)), true, true, false, true, false,
|
||||
true, false, true, false, false,
|
||||
false, false, false, false, false,
|
||||
true, false, true, false, true,
|
||||
ispod && true, ispod && true, ispod && true, false, true);
|
||||
|
||||
/** Const Reference Variable tests */
|
||||
|
||||
// This will always be seen as a const
|
||||
const T*cip = &i;
|
||||
passed &= do_test<T>(var(cip), true, true, false, true, false,
|
||||
true, false, true, false, false,
|
||||
false, false, false, false, false,
|
||||
true, false, true, false, true,
|
||||
ispod && true, ispod && true, ispod && true, false, true);
|
||||
|
||||
// make sure const of const works
|
||||
passed &= do_test<T>(const_var(cip), true, true, false, true, false,
|
||||
true, false, true, false, false,
|
||||
false, false, false, false, false,
|
||||
true, false, true, false, true,
|
||||
ispod && true, ispod && true, ispod && true, false, true);
|
||||
|
||||
/** shared_ptr tests **/
|
||||
|
||||
boost::shared_ptr<T> ip(new T(initial));
|
||||
|
||||
passed &= do_test<T>(var(ip), true, true, true, true, true,
|
||||
true, true, true, true, true,
|
||||
true, true, true, true, true,
|
||||
true, true, true, true, true,
|
||||
ispod && true, ispod && true, ispod && true, true, true);
|
||||
|
||||
passed &= do_test<T>(const_var(ip), true, true, false, true, false,
|
||||
true, false, true, false, true,
|
||||
false, true, false, true, false,
|
||||
true, false, true, false, true,
|
||||
ispod && true, ispod && true, ispod && true, false, true);
|
||||
|
||||
/** const shared_ptr tests **/
|
||||
boost::shared_ptr<const T> ipc(new T(initial));
|
||||
|
||||
passed &= do_test<T>(var(ipc), true, true, false, true, false,
|
||||
true, false, true, false, true,
|
||||
false, true, false, true, false,
|
||||
true, false, true, false, true,
|
||||
ispod && true, ispod && true, ispod && true, false, true);
|
||||
|
||||
// const of this should be the same, making sure it compiles
|
||||
passed &= do_test<T>(const_var(ipc), true, true, false, true, false,
|
||||
true, false, true, false, true,
|
||||
false, true, false, true, false,
|
||||
true, false, true, false, true,
|
||||
ispod && true, ispod && true, ispod && true, false, true);
|
||||
|
||||
|
||||
/** Double ptr tests **/
|
||||
|
||||
/*
|
||||
T **doublep;
|
||||
|
||||
passed &= do_test<T*>(var(doublep), true, true, false, true, false,
|
||||
true, false, true, false, true,
|
||||
false, true, false, true, false,
|
||||
true, false, true, false, true,
|
||||
ispod && true, ispod && true, ispod && true, false, true);
|
||||
*/
|
||||
|
||||
return passed;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
bool pointer_test(const T& default_value, const T& new_value)
|
||||
{
|
||||
T *p = new T(default_value);
|
||||
|
||||
// we store a pointer to a pointer, so we can get a pointer to a pointer
|
||||
try {
|
||||
T **result = boxed_cast<T **>(var(&p));
|
||||
*(*result) = new_value;
|
||||
|
||||
|
||||
if (p != (*result) ) {
|
||||
std::cerr << "Pointer passed in different than one returned" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (*p != *(*result) ) {
|
||||
std::cerr << "Somehow dereferenced pointer values are not the same?" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (const exception::bad_boxed_cast &) {
|
||||
std::cerr << "Bad boxed cast performing ** to ** test" << std::endl;
|
||||
return false;
|
||||
} catch (...) {
|
||||
std::cerr << "Unknown exception performing ** to ** test" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
bool passed = true;
|
||||
|
||||
/*
|
||||
bool T, bool ConstT, bool TRef, bool ConstTRef, bool TPtr,
|
||||
bool ConstTPtr, bool TPtrConst, bool ConstTPtrConst, bool SharedPtrT, bool SharedConstPtrT,
|
||||
bool ConstSharedPtrT, bool ConstSharedConstPtrT, bool ConstSharedPtrTRef, bool ConstSharedPtrTConstRef, bool BoostRef,
|
||||
bool BoostConstRef, bool ConstBoostRef, bool ConstBoostConstRef, bool ConstBoostRefRef, bool ConstBoostConstRefRef,
|
||||
bool Number, bool ConstNumber, bool ConstNumberRef
|
||||
*/
|
||||
|
||||
passed &= built_in_type_test<int>(5, true);
|
||||
passed &= built_in_type_test<double>(1.1, true);
|
||||
passed &= built_in_type_test<char>('a', true);
|
||||
passed &= built_in_type_test<uint8_t>('a', true);
|
||||
passed &= built_in_type_test<int64_t>('a', true);
|
||||
passed &= built_in_type_test<bool>(false, false);
|
||||
passed &= built_in_type_test<std::string>("Hello World", false);
|
||||
|
||||
// storing a pointer
|
||||
passed &= pointer_test<int>(1, 0);
|
||||
|
||||
if (passed)
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
#include <chaiscript/utility/utility.hpp>
|
||||
|
||||
template<typename LHS, typename RHS>
|
||||
void assert_equal(const LHS &lhs, const RHS &rhs)
|
||||
{
|
||||
if (lhs==rhs)
|
||||
{
|
||||
return;
|
||||
} else {
|
||||
std::cout << "Got: " << lhs << " expected " << rhs << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
chaiscript::ChaiScript chai;
|
||||
|
||||
chai("attr bob::z; def bob::bob() { this.z = 10 }; var x = bob()");
|
||||
|
||||
chaiscript::dispatch::Dynamic_Object &mydo = chai.eval<chaiscript::dispatch::Dynamic_Object &>("x");
|
||||
|
||||
assert_equal(mydo.get_type_name(), "bob");
|
||||
|
||||
assert_equal(chaiscript::boxed_cast<int>(mydo.get_attr("z")), 10);
|
||||
|
||||
chai("x.z = 15");
|
||||
|
||||
assert_equal(chaiscript::boxed_cast<int>(mydo.get_attr("z")), 15);
|
||||
|
||||
int &z = chaiscript::boxed_cast<int&>(mydo.get_attr("z"));
|
||||
|
||||
assert_equal(z, 15);
|
||||
|
||||
z = 20;
|
||||
|
||||
assert_equal(z, 20);
|
||||
|
||||
assert_equal(chaiscript::boxed_cast<int>(chai("x.z")), 20);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
}
|
||||
@ -1,122 +0,0 @@
|
||||
// Tests to make sure that the order in which function dispatches occur is correct
|
||||
|
||||
#include <chaiscript/chaiscript.hpp>
|
||||
|
||||
int test_generic()
|
||||
{
|
||||
chaiscript::ChaiScript chai;
|
||||
|
||||
try {
|
||||
chai.eval("throw(runtime_error(\"error\"));");
|
||||
} catch (const chaiscript::Boxed_Value &bv) {
|
||||
const std::exception &e = chaiscript::boxed_cast<const std::exception &>(bv);
|
||||
if (e.what() == std::string("error"))
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "test_generic failed" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int test_1()
|
||||
{
|
||||
chaiscript::ChaiScript chai;
|
||||
|
||||
try {
|
||||
chai.eval("throw(1)", chaiscript::exception_specification<int>());
|
||||
} catch (int e) {
|
||||
if (e == 1)
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "test_1 failed" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int test_2()
|
||||
{
|
||||
chaiscript::ChaiScript chai;
|
||||
|
||||
try {
|
||||
chai.eval("throw(1.0)", chaiscript::exception_specification<int, double>());
|
||||
} catch (const double e) {
|
||||
if (e == 1.0)
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "test_2 failed" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int test_5()
|
||||
{
|
||||
chaiscript::ChaiScript chai;
|
||||
|
||||
try {
|
||||
chai.eval("throw(runtime_error(\"error\"))", chaiscript::exception_specification<int, double, float, const std::string &, const std::exception &>());
|
||||
} catch (const double e) {
|
||||
std::cout << "test_5 failed with double" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
} catch (int) {
|
||||
std::cout << "test_5 failed with int" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
} catch (float) {
|
||||
std::cout << "test_5 failed with float" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
} catch (const std::string &) {
|
||||
std::cout << "test_5 failed with string" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
} catch (const std::exception &e) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
std::cout << "test_5 failed" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int test_unhandled()
|
||||
{
|
||||
chaiscript::ChaiScript chai;
|
||||
|
||||
try {
|
||||
chai.eval("throw(\"error\")", chaiscript::exception_specification<int, double, float, const std::exception &>());
|
||||
} catch (double) {
|
||||
std::cout << "test_unhandled failed with double" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
} catch (int) {
|
||||
std::cout << "test_unhandled failed with int" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
} catch (float) {
|
||||
std::cout << "test_unhandled failed with float" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
} catch (const std::exception &e) {
|
||||
std::cout << "test_unhandled failed with std::exception" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
} catch (const chaiscript::Boxed_Value &bv) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
std::cout << "test_unhandled failed" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
if (test_generic() == EXIT_SUCCESS
|
||||
&& test_1() == EXIT_SUCCESS
|
||||
&& test_2() == EXIT_SUCCESS
|
||||
&& test_5() == EXIT_SUCCESS
|
||||
&& test_unhandled() == EXIT_SUCCESS)
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
// Tests to make sure that the order in which function dispatches occur is correct
|
||||
|
||||
#include <chaiscript/utility/utility.hpp>
|
||||
|
||||
int test_one(const int &)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test_two(int &)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
chaiscript::ChaiScript chai;
|
||||
chai.eval("def test_fun(x) { return 3; }");
|
||||
chai.eval("def test_fun(x) : x == \"hi\" { return 4; }");
|
||||
chai.eval("def test_fun(x) { return 5; }");
|
||||
chai.add(chaiscript::fun(&test_one), "test_fun");
|
||||
chai.add(chaiscript::fun(&test_two), "test_fun");
|
||||
|
||||
int res1 = chai.eval<int>("test_fun(1)");
|
||||
int res2 = chai.eval<int>("var i = 1; test_fun(i)");
|
||||
int res3 = chai.eval<int>("test_fun(\"bob\")");
|
||||
int res4 = chai.eval<int>("test_fun(\"hi\")");
|
||||
|
||||
if (res1 == 1
|
||||
&& res2 == 2
|
||||
&& res3 == 3
|
||||
&& res4 == 4 )
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
#include <chaiscript/utility/utility.hpp>
|
||||
|
||||
double test_call(const boost::function<double (int)> &f, int val)
|
||||
{
|
||||
return f(val);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
chaiscript::ChaiScript chai;
|
||||
|
||||
chai.add(chaiscript::fun(&test_call), "test_call");
|
||||
|
||||
chai.eval("def func(i) { return i * 3.5; };");
|
||||
double d = chai.eval<double>("test_call(func, 3)");
|
||||
|
||||
if (d == 3 * 3.5)
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
#include <chaiscript/utility/utility.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
chaiscript::ChaiScript chai;
|
||||
|
||||
chai.eval("def func() { print(\"Hello World\"); } ");
|
||||
|
||||
boost::function<void ()> f = chai.eval<boost::function<void ()> >("func");
|
||||
f();
|
||||
|
||||
if (chai.eval<boost::function<std::string (int)> >("to_string")(6) != "6")
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (chai.eval<boost::function<std::string (const chaiscript::Boxed_Value &)> >("to_string")(chaiscript::var(6)) == "6")
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
#include "multifile_test_chai.hpp"
|
||||
|
||||
Multi_Test_Chai::Multi_Test_Chai()
|
||||
: m_chai(new chaiscript::ChaiScript())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
boost::shared_ptr<chaiscript::ChaiScript> Multi_Test_Chai::get_chai()
|
||||
{
|
||||
return m_chai;
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
#include <chaiscript/chaiscript.hpp>
|
||||
|
||||
class Multi_Test_Chai
|
||||
{
|
||||
public:
|
||||
Multi_Test_Chai();
|
||||
|
||||
boost::shared_ptr<chaiscript::ChaiScript> get_chai();
|
||||
|
||||
private:
|
||||
boost::shared_ptr<chaiscript::ChaiScript> m_chai;
|
||||
};
|
||||
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
#include "multifile_test_chai.hpp"
|
||||
#include "multifile_test_module.hpp"
|
||||
|
||||
#include <chaiscript/chaiscript.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
Multi_Test_Chai chaitest;
|
||||
Multi_Test_Module chaimodule;
|
||||
|
||||
boost::shared_ptr<chaiscript::ChaiScript> chai = chaitest.get_chai();
|
||||
chai->add(chaimodule.get_module());
|
||||
return chai->eval<int>("get_module_value()");
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
#include <chaiscript/chaiscript.hpp>
|
||||
|
||||
#include "multifile_test_module.hpp"
|
||||
|
||||
Multi_Test_Module::Multi_Test_Module()
|
||||
{
|
||||
}
|
||||
|
||||
int Multi_Test_Module::get_module_value()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
chaiscript::ModulePtr Multi_Test_Module::get_module()
|
||||
{
|
||||
chaiscript::ModulePtr module(new chaiscript::Module());
|
||||
|
||||
module->add(chaiscript::fun(&Multi_Test_Module::get_module_value), "get_module_value");
|
||||
|
||||
return module;
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
#include <chaiscript/chaiscript.hpp>
|
||||
|
||||
class Multi_Test_Module
|
||||
{
|
||||
public:
|
||||
static int get_module_value();
|
||||
|
||||
Multi_Test_Module();
|
||||
|
||||
chaiscript::ModulePtr get_module();
|
||||
};
|
||||
@ -1,66 +0,0 @@
|
||||
#include <chaiscript/utility/utility.hpp>
|
||||
|
||||
class Test
|
||||
{
|
||||
public:
|
||||
Test()
|
||||
{
|
||||
++count();
|
||||
}
|
||||
|
||||
Test(const Test &)
|
||||
{
|
||||
++count();
|
||||
}
|
||||
|
||||
~Test()
|
||||
{
|
||||
--count();
|
||||
}
|
||||
|
||||
static int& count()
|
||||
{
|
||||
static int c = 0;
|
||||
return c;
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module());
|
||||
|
||||
CHAISCRIPT_CLASS( m,
|
||||
Test,
|
||||
(Test ())
|
||||
(Test (const Test &)),
|
||||
((count))
|
||||
);
|
||||
|
||||
chaiscript::ChaiScript chai;
|
||||
chai.add(m);
|
||||
chai.add(chaiscript::fun(&Test::count), "count");
|
||||
|
||||
int count = chai.eval<int>("count()");
|
||||
|
||||
int count2 = chai.eval<int>("var i = 0; { var t = Test(); } return i;");
|
||||
|
||||
int count3 = chai.eval<int>("var i = 0; { var t = Test(); i = count(); } return i;");
|
||||
|
||||
int count4 = chai.eval<int>("var i = 0; { var t = Test(); { var t2 = Test(); i = count(); } } return i;");
|
||||
|
||||
int count5 = chai.eval<int>("var i = 0; { var t = Test(); { var t2 = Test(); } i = count(); } return i;");
|
||||
|
||||
int count6 = chai.eval<int>("var i = 0; { var t = Test(); { var t2 = Test(); } } i = count(); return i;");
|
||||
|
||||
if (count == 0
|
||||
&& count2 == 0
|
||||
&& count3 == 1
|
||||
&& count4 == 2
|
||||
&& count5 == 1
|
||||
&& count6 == 0)
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
#include <chaiscript/utility/utility.hpp>
|
||||
|
||||
class Test {
|
||||
public:
|
||||
Test() : value_(5) {}
|
||||
|
||||
short get_value() { return value_; }
|
||||
|
||||
short value_;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
chaiscript::ChaiScript chai;
|
||||
chai.add(chaiscript::user_type<Test>(), "Test");
|
||||
chai.add(chaiscript::constructor<Test()>(), "Test");
|
||||
|
||||
chai.add(chaiscript::fun(&Test::get_value), "get_value");
|
||||
|
||||
chai.eval("var t := Test();");
|
||||
|
||||
if (chai.eval<bool>("t.get_value() == 5"))
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
// Tests to make sure that the order in which function dispatches occur is correct
|
||||
|
||||
#include <chaiscript/dispatchkit/type_info.hpp>
|
||||
|
||||
void test_type(const chaiscript::Type_Info &ti, bool t_is_const, bool t_is_pointer, bool t_is_reference, bool t_is_void,
|
||||
bool t_is_undef)
|
||||
{
|
||||
if (ti.is_const() == t_is_const
|
||||
&& ti.is_pointer() == t_is_pointer
|
||||
&& ti.is_reference() == t_is_reference
|
||||
&& ti.is_void() == t_is_void
|
||||
&& ti.is_undef() == t_is_undef)
|
||||
{
|
||||
return;
|
||||
} else {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
test_type(chaiscript::user_type<void>(), false, false, false, true, false);
|
||||
test_type(chaiscript::user_type<const int>(), true, false, false, false, false);
|
||||
test_type(chaiscript::user_type<const int &>(), true, false, true, false, false);
|
||||
test_type(chaiscript::user_type<int>(), false, false, false, false, false);
|
||||
test_type(chaiscript::user_type<int *>(), false, true, false, false, false);
|
||||
test_type(chaiscript::user_type<const int *>(), true, true, false, false, false);
|
||||
test_type(chaiscript::Type_Info(), false, false, false, false, true);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
#include <chaiscript/utility/utility.hpp>
|
||||
|
||||
class Test
|
||||
{
|
||||
public:
|
||||
void function() {}
|
||||
std::string function2() { return "Function2"; }
|
||||
void function3() {}
|
||||
std::string functionOverload(double) { return "double"; }
|
||||
std::string functionOverload(int) { return "int"; }
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module());
|
||||
|
||||
CHAISCRIPT_CLASS( m,
|
||||
Test,
|
||||
(Test ())
|
||||
(Test (const Test &)),
|
||||
((function))
|
||||
((function2))
|
||||
((function3))
|
||||
((functionOverload)(std::string (Test::*)(double)))
|
||||
((functionOverload)(std::string (Test::*)(int)))
|
||||
((operator=))
|
||||
);
|
||||
|
||||
chaiscript::ChaiScript chai;
|
||||
chai.add(m);
|
||||
if (chai.eval<std::string>("var t = Test(); t.function2(); ") == "Function2"
|
||||
&& chai.eval<std::string>("var t = Test(); t.functionOverload(1); ") == "int"
|
||||
&& chai.eval<std::string>("var t = Test(); t.functionOverload(1.1); ") == "double")
|
||||
{
|
||||
chai.eval("t = Test();");
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user