Beispiel #1
0
KAGUYA_TEST_FUNCTION_DEF(luaL_requiref_test)(kaguya::State& s)
{
	using namespace kaguya;

	luaL_requiref(s.state(),"mylib", lua_mylibf,false);
	kaguya::LuaStackRef ref(s.state(), -1,true);
	TEST_EQUAL(ref["value"],111);
	TEST_CHECK(s("assert(mylib == nil)"));
}
Beispiel #2
0
KAGUYA_TEST_FUNCTION_DEF(lua_compare_test)(kaguya::State& s)
{
	using namespace kaguya;

	s.pushToStack(2);
	s.pushToStack(2);
	TEST_CHECK(lua_compare(s.state(), -2, -1, LUA_OPEQ));
	TEST_CHECK(lua_compare(s.state(), -2, -1, LUA_OPLE));
	TEST_CHECK(!lua_compare(s.state(), -2, -1, LUA_OPLT));
	TEST_CHECK(!lua_compare(s.state(), -2, -1, LUA_OPLE + 2));//invalid option
	s.popFromStack();
	s.popFromStack();

	s.pushToStack(4);
	s.pushToStack(2);
	TEST_CHECK(!lua_compare(s.state(), -2, -1, LUA_OPEQ));
	TEST_CHECK(!lua_compare(s.state(), -2, -1, LUA_OPLE));
	TEST_CHECK(!lua_compare(s.state(), -2, -1, LUA_OPLT));
	TEST_CHECK(!lua_compare(s.state(), -2, -1, LUA_OPLE + 2));//invalid option
	s.popFromStack();
	s.popFromStack();

	s.pushToStack(2);
	s.pushToStack(4);
	TEST_CHECK(!lua_compare(s.state(), -2, -1, LUA_OPEQ));
	TEST_CHECK(lua_compare(s.state(), -2, -1, LUA_OPLE));
	TEST_CHECK(lua_compare(s.state(), -2, -1, LUA_OPLT));
	TEST_CHECK(!lua_compare(s.state(), -2, -1, LUA_OPLE + 2));//invalid option
	s.popFromStack();
	s.popFromStack();
}
Beispiel #3
0
KAGUYA_TEST_FUNCTION_DEF(native_function_call_test)(kaguya::State& state)
{
	using namespace kaguya::nativefunction;
	Foo foo;
	state.newRef(6).push();
	state.newRef(9).push();
	state.newRef(2).push();

	call(state.state(), &free_standing_function);

	lua_settop(state.state(), 0);
	state.newRef(&foo).push();
	state.newRef("Bar").push();
	call(state.state(), &Foo::setBar);

	lua_settop(state.state(), 0);
#if KAGUYA_USE_CPP11
	state.newRef(&foo).push();
	state.newRef(9).push();
	call(state.state(), [](Foo* foo, int b) {
		TEST_EQUAL(b, 9);
		foo->setBar("fromlambda");
	});
	TEST_EQUAL(foo.bar, "fromlambda");

	std::string capture("capture");
	call(state.state(), [=](Foo* foo, int b) {
		TEST_EQUAL(b, 9);
		foo->setBar(capture + "lambda");
	});
	TEST_EQUAL(foo.bar, "capturelambda");
#endif

	lua_settop(state.state(), 0);
}
Beispiel #4
0
KAGUYA_TEST_FUNCTION_DEF(lua_resume_test)(kaguya::State& s)
{
	using namespace kaguya;

	
	LuaThread t = s.newThread(s.loadstring("v={...}"));

	lua_State* co = t.get<lua_State*>();
	lua_pushnumber(co, 2);
	lua_pushnumber(co, 3);

	lua_resume(co,s.state(),2);

	TEST_EQUAL(s["v"][1], 2);
	TEST_EQUAL(s["v"][2], 3);
}
Beispiel #5
0
KAGUYA_TEST_FUNCTION_DEF(stackValueDump)(kaguya::State& s)
{
	using namespace kaguya;
	util::stackValueDump(std::cout, s.state(), 4, 2);
}