Ejemplo n.º 1
0
void LoggerSingleton::LoggerBinder::reg( LuaStatePtr state )
{
    using namespace luabind;
    module( state.get() )
    [
        def( "log", &LoggerSingleton::LoggerBinder::logWrapper )
    ];
}
Ejemplo n.º 2
0
TEST(UserDataTest, MethodsOnly) {
  auto L = GL.get();
  const char chunk[] =
    "return function(obj)\n"
    "    return obj:value()\n"
    "end\n";
  ASSERT_EQ(0, luaL_loadstring(L, chunk));
  ASSERT_EQ(0, lua_pcall(L, 0, 1, 0))
    << luaGetChecked<folly::StringPiece>(L, -1);
  pushUserData<TestObjectMethodsOnly>(L);
  ASSERT_EQ(0, lua_pcall(L, 1, 1, 0))
    << luaGetChecked<folly::StringPiece>(L, -1);
  EXPECT_EQ(42, luaGetChecked<int>(L, -1));
  lua_pop(L, 1);
}
Ejemplo n.º 3
0
TEST(UserDataTest, Destruction) {
  TestObject::destructorCalled = false;
  TestObject::gcCalled = false;
  auto L = GL.get();
  auto& obj = pushUserData<TestObject>(L, 42);
  EXPECT_EQ(42, obj.x);
  auto p = getUserData<TestObject>(L, -1);
  EXPECT_EQ(&obj, p);
  EXPECT_FALSE(TestObject::gcCalled);
  EXPECT_FALSE(TestObject::destructorCalled);
  lua_pop(L, 1);
  lua_gc(L, LUA_GCCOLLECT, 0);
  lua_gc(L, LUA_GCCOLLECT, 0);
  EXPECT_TRUE(TestObject::gcCalled);
  EXPECT_TRUE(TestObject::destructorCalled);
}
Ejemplo n.º 4
0
TEST(SimpleObjectTest, Simple) {
  auto L = GL.get();
  auto& obj = pushObject<SimpleTestObject>(L, 42);
  EXPECT_EQ(42, obj.x);

  EXPECT_EQ(&obj, getObject<SimpleTestObject>(L, -1));
  EXPECT_EQ(&obj, &getObjectChecked<SimpleTestObject>(L, -1));

  lua_gc(L, LUA_GCCOLLECT, 0);
  lua_gc(L, LUA_GCCOLLECT, 0);
  EXPECT_FALSE(SimpleTestObject::destructorCalled);
  lua_pop(L, 1);
  lua_gc(L, LUA_GCCOLLECT, 0);
  lua_gc(L, LUA_GCCOLLECT, 0);
  EXPECT_TRUE(SimpleTestObject::destructorCalled);
}
Ejemplo n.º 5
0
TEST(UserDataTest, MethodsAndIndex) {
  auto L = GL.get();
  const char chunk[] =
    "return function(obj)\n"
    "    obj.y = 100\n"
    "    return obj:value(), #obj, obj.y\n"
    "end\n";
  ASSERT_EQ(0, luaL_loadstring(L, chunk));
  ASSERT_EQ(0, lua_pcall(L, 0, 1, 0))
    << luaGetChecked<folly::StringPiece>(L, -1);
  pushUserData<TestObject>(L, 42);
  ASSERT_EQ(0, lua_pcall(L, 1, 3, 0))
    << luaGetChecked<folly::StringPiece>(L, -1);
  EXPECT_EQ(42, luaGetChecked<int>(L, -3));
  EXPECT_EQ(10, luaGetChecked<int>(L, -2));
  EXPECT_EQ(100, luaGetChecked<int>(L, -1));
  lua_pop(L, 3);
}
Ejemplo n.º 6
0
	void OsgAppProxy::bindToLua(LuaStatePtr & state) {
		// Bind this class
		if (state) {
#ifdef VERBOSE
			VRJLUA_MSG_START(dbgVRJLUA_PROXY, MSG_STATUS)
			        << "Registering vrj.OsgAppProxy with Lua"
			        << VRJLUA_MSG_END(dbgVRJLUA_PROXY, MSG_STATUS);
#endif
			using namespace luabind;
			module(state.get(), "vrjApp") [
			    class_<OsgAppProxy>("OsgAppProxy")
			    .def(constructor<>())
			    .def("setAppDelegate", & OsgAppProxy::setAppDelegate)
			    .def("getAppDelegate", & OsgAppProxy::getAppDelegate)
			    .def("setActiveApplication", & OsgAppProxy::setActiveApplication)
			    .def("getScene", & OsgAppProxy::getScene)
			    .def("getTimeDelta", & OsgAppProxy::getTimeDelta)
			];
		}
	}
Ejemplo n.º 7
0
	SynchronizedRunBuffer::SynchronizedRunBuffer(LuaStatePtr const& state) :
		_init(false) {
		/// @todo own this state? How?
		_state = state.get();
	}
Ejemplo n.º 8
0
void LuaPath::addLuaRequirePath(LuaStatePtr state, std::string const& dirEndingInSlash) {
    LuaSearchPathUpdater searchpath(state.get());

    searchpath.extend(SearchDirectory(dirEndingInSlash));
}