lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

At 2003-06-07 11:51, you wrote:

Simple question, how to pass class pointer as argument to LUA function ?
I use LUA 5.0 And LuaBind
I've registered some class members:

luabind::class_<c_FOO>(g_L, "c_FOO")
                            .def("Do", &c_FOO::Do)
                            .def("DoOther", &c_FOO::DoOther)

And now (in C++) I have method like this:

void c_FOO::CallSomeLuaFunction()
  // And now I need to call 'function Lua_Foo(arg1)'
  // where arg1 is a 'this'
  // and inside call some of c_FOO methods
  // arg1:Do() for example

  lua_pushstring(g_L, "LuaFoo");
  lua_gettable(g_L, LUA_GLOBALSINDEX);
  lua_pushstring(g_L, "this");
  lua_call(g_L, 1, 0);

  // The code above do nothing, how to modify it ???

What you can do inside your CallSomeLuaFunction() is:

luabind::call_function<void>(L, "LuaFoo", this);

If the 'LuaFoo'-function returns something you can give the return type instead of void as template parameter. It will use the appropriate converters to convert the 'this'-pointer to a lua value.

You could have a look at the luabind::functor template too.

There is a mailing list for luabind which may be more suited for this kind of question.

Arvid Norberg