user2887378
user2887378

Reputation:

call lua callback with custom data as function argument

I'm just looking for solution how to pass object from C to lua callback as function argument, is it even possible? I cannot find any referece. just trying something like this:

luabind::call_function(State, "Callback_name", object);

but luabind is not a option in this case because it is obsolete and additionally some features just don't work that's probably because of boost as I read but don't know exactly, thats why I switched to toLua++ but still cannot find any solution for it. I'm just trying to achieve to access data from C in lua callback ex:

function LUA_Callback(object1, object2)
    print(object1.name)
    print(object2.size)
end

Is there any way to solve it or library(without boost) to do this?

Upvotes: 1

Views: 404

Answers (1)

Mud
Mud

Reputation: 29000

That depends on what you mean by "push object". It's trivial to push numbers, strings, C functions, tables, etc. -- in other words, Lua objects -- using API routines like lua_pushstring, lua_pushnumber, etc.

If you're talking about pushing C++ objects, you need to create and push userdata. If you want them to behave like objects from Lua, then you'll need the appropriate metatable/methods.

Upvotes: 1

Related Questions