本文整理汇总了C++中kaguya::State::state方法的典型用法代码示例。如果您正苦于以下问题:C++ State::state方法的具体用法?C++ State::state怎么用?C++ State::state使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kaguya::State
的用法示例。
在下文中一共展示了State::state方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ref
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)"));
}
示例2:
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();
}
示例3: capture
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);
}