lua-users home
lua-l archive

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


class A { public: int var; };

void some_host_program_function(void) {
A *ptr_to_a;
ptr_to_a = new A();
// execute a lua function and pass ptr_to_a as a parameter
// How i Do that?
}

// untested & from memory so you may want to check it! Havent had any coffee
yet either :-)
lua_getglobal(ls,"myfunc");
ASSERT(lua_isfunction(ls,-1));
lua_pushusertag(ls,(void*)ptr_to_a,tolua_tag("A"));
lua_call(ls,1,0);

>>Also, i want to know if is possible to.. instantiate a new A object in
lua.. then pass it back (via the return of a function) to the host
program.

-- lua code
a_inst = A:new()  -- new() creates the object by return? See toLua docs for
ownership.
a_wrapped_func(a_inst);

// C code header & pkg
void a_wrapped_func(A* a);

>>And third, how do to pass "functors" to a function in lua?, maybe for...
i have a lua gui loop, and the callbacks must be executed in c++.. so..
i want to call the lua function set_callback() with a C++ "functor" as
argument. (and four :), can i set these functors callbacks in tag methods?)

Now I need coffee.