Skip to main content
gamedev.net
🔒 Locked

LUA callback / tables

Started by HellSlayer Aug 22, 2008 at 6:05 AM 0 replies 1k views
Original Post
HellSlayer
HellSlayer
Hey guys, I have this scenario: I want to enable my scripts to react to events, so I added a userdata data type to lua (EventHandler) EventHandler is basically a table that has the function RegisterEvent (a C-function) an exmample would be: eh = EventHandler.new() eh:RegisterEvent("GAME_STOP") function eh:OnEvent(event) -- do something end Now I wonder how to get the name of the table (or a refernce to it) so i can callback foo.OnEvent(event, ...) The callback basically looks like this: lua_getglobal(L, "foo"); lua_getfield(L, 1, "OnEvent"); lua_call(L, 1, 0); But I need to replace "foo" with something my C function for RegisterEvent gets when it is being called.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.