Exemplo n.º 1
0
KAGUYA_TEST_FUNCTION_DEF(void_defaultarguments)(kaguya::State& state)
{
	KAGUYA_VOID_FUNCTION_OVERLOADS(defargfn_wrapper, void_defargfn,0,3)

	state["defargfn"] = kaguya::function(defargfn_wrapper);

	state.dostring("defargfn()");
	state.dostring("defargfn(3)");
	state.dostring("defargfn(3,2)");
	state.dostring("defargfn(3,2,1)");
}
Exemplo n.º 2
0
KAGUYA_TEST_FUNCTION_DEF(defaultarguments)(kaguya::State& state)
{
	KAGUYA_FUNCTION_OVERLOADS(defargfn_wrapper, defargfn,0,3)

	state["defargfn"] = kaguya::function(defargfn_wrapper);

	state.dostring("assert(defargfn() == 6)");
	state.dostring("assert(defargfn(6) == 12)");
	state.dostring("assert(defargfn(6,5) == 30)");
	state.dostring("assert(defargfn(2,2,2) == 8)");
}
Exemplo n.º 3
0
KAGUYA_TEST_FUNCTION_DEF(load_with_other_env)(kaguya::State& state)
{
	state.dostring("foo = 'bar'");

	state["otherEnv"] = kaguya::NewTable();

	state.dostring("foo = 'dar'", state["otherEnv"]);

	TEST_CHECK(state("assert(foo == 'bar')"));

	TEST_CHECK(state("assert(otherEnv.foo == 'dar')"));
}
Exemplo n.º 4
0
KAGUYA_TEST_FUNCTION_DEF(defaultarguments)(kaguya::State& state)
{
	state.setErrorHandler(error_fun);
	state["defargfn"] = kaguya::function(defargfn_wrapper());
	state["defargfn2"] = kaguya::function(defargfn_wrapper2());

	state.dostring("defargfn('abc')");
	last_error_message.find("[OPT]int,[OPT]int,[OPT]int");


	state.dostring("defargfn2('abc')");
	last_error_message.find("int,int,[OPT]int");
}
Exemplo n.º 5
0
KAGUYA_TEST_FUNCTION_DEF(member_function_defaultarguments)(kaguya::State& state)
{
	KAGUYA_MEMBER_FUNCTION_OVERLOADS(defargfn_wrapper, TestClass, default_arg, 0, 3)

	state["TestClass"].setClass(kaguya::UserdataMetatable<TestClass>()
		.setConstructors<TestClass()>()
		.addFunction("defargfn", defargfn_wrapper)
	);

	state.dostring("test = TestClass.new()");

	state.dostring("assert(test:defargfn() == 6)");
	state.dostring("assert(test:defargfn(6) == 12)");
	state.dostring("assert(test:defargfn(6,5) == 30)");
	state.dostring("assert(test:defargfn(2,2,2) == 8)");
}
Exemplo n.º 6
0
KAGUYA_TEST_FUNCTION_DEF(defaultarguments)(kaguya::State& state)
{
	state.setErrorHandler(error_fun);
	state["defargfn"] = kaguya::function(defargfn_wrapper());
	state["defargfn2"] = kaguya::function(defargfn_wrapper2());

	std::string intname = kaguya::util::pretty_name(typeid(int));

	if (intname == "int")
	{
		state.dostring("defargfn('abc')");
		TEST_CHECK_M(last_error_message.find("[OPT]int,[OPT]int,[OPT]int") != std::string::npos, last_error_message);
		state.dostring("defargfn2('abc',3)");
		TEST_CHECK_M(last_error_message.find("int,int,[OPT]int") != std::string::npos, last_error_message);
	}
}
Exemplo n.º 7
0
KAGUYA_TEST_FUNCTION_DEF(luacfunction)(kaguya::State& state)
{
	state["cfunction"] = &cfunction;

	state.dostring("cfunction(3)");


}