summaryrefslogtreecommitdiff
path: root/library/LuaTypes.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-04-05 11:59:39 +0400
committerAlexander Gavrilov2012-04-05 11:59:39 +0400
commit3afed43cdb435c788964d983a358d97ee291c2fc (patch)
tree231d57551e1d9ff3ef8dedf7d29a265e23adf6ec /library/LuaTypes.cpp
parentd1b27418a6a39aa15d51465e61975c5230dcc9d6 (diff)
downloaddfhack-3afed43cdb435c788964d983a358d97ee291c2fc.tar.gz
dfhack-3afed43cdb435c788964d983a358d97ee291c2fc.tar.bz2
dfhack-3afed43cdb435c788964d983a358d97ee291c2fc.tar.xz
Experimental: try wrapping a dfhack api function.
Diffstat (limited to 'library/LuaTypes.cpp')
-rw-r--r--library/LuaTypes.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/library/LuaTypes.cpp b/library/LuaTypes.cpp
index 6d5961f8..2cc929ee 100644
--- a/library/LuaTypes.cpp
+++ b/library/LuaTypes.cpp
@@ -1029,11 +1029,16 @@ static int meta_call_function(lua_State *state)
/**
* Create a closure invoking the given function, and add it to the field table.
*/
-static void AddMethodWrapper(lua_State *state, int meta_idx, int field_idx,
- const char *name, function_identity_base *fun)
+void LuaWrapper::AddMethodWrapper(lua_State *state, int meta_idx, int field_idx,
+ const char *name, function_identity_base *fun)
{
+ field_idx = lua_absindex(state, field_idx);
+
lua_rawgetp(state, LUA_REGISTRYINDEX, &DFHACK_TYPETABLE_TOKEN);
- lua_pushvalue(state, meta_idx);
+ if (meta_idx)
+ lua_pushvalue(state, meta_idx);
+ else
+ lua_pushlightuserdata(state, NULL); // can't be a metatable
lua_pushfstring(state, "%s()", name);
lua_pushlightuserdata(state, fun);
lua_pushcclosure(state, meta_call_function, 4);