summaryrefslogtreecommitdiffstats
path: root/source/ManualBindings.cpp
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-10-11 16:02:09 +0200
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-10-11 16:02:09 +0200
commite421e9077c61465b2073b0f6428cdb53e3bfbce8 (patch)
tree314a7f9dd468e8c322c88d1bf0ba4b7acde3333e /source/ManualBindings.cpp
parentAdded functionality so one plugin can call functions on another plugin :D (diff)
downloadcuberite-e421e9077c61465b2073b0f6428cdb53e3bfbce8.tar
cuberite-e421e9077c61465b2073b0f6428cdb53e3bfbce8.tar.gz
cuberite-e421e9077c61465b2073b0f6428cdb53e3bfbce8.tar.bz2
cuberite-e421e9077c61465b2073b0f6428cdb53e3bfbce8.tar.lz
cuberite-e421e9077c61465b2073b0f6428cdb53e3bfbce8.tar.xz
cuberite-e421e9077c61465b2073b0f6428cdb53e3bfbce8.tar.zst
cuberite-e421e9077c61465b2073b0f6428cdb53e3bfbce8.zip
Diffstat (limited to 'source/ManualBindings.cpp')
-rw-r--r--source/ManualBindings.cpp27
1 files changed, 25 insertions, 2 deletions
diff --git a/source/ManualBindings.cpp b/source/ManualBindings.cpp
index dc96800d3..9ddd1360e 100644
--- a/source/ManualBindings.cpp
+++ b/source/ManualBindings.cpp
@@ -737,8 +737,29 @@ static int copy_lua_values(lua_State * a_Source, lua_State * a_Destination, int
tolua_pushnumber(a_Destination, d );
}
break;
+ case LUA_TUSERDATA:
+ {
+ const char * type = 0;
+ if (lua_getmetatable(a_Source,i))
+ {
+ lua_rawget(a_Source, LUA_REGISTRYINDEX);
+ type = lua_tostring(a_Source, -1);
+ lua_pop(a_Source, 1); // Pop.. something?! I don't knooow~~ T_T
+ }
+
+ // don't need tolua_tousertype we already have the type
+ void * ud = tolua_touserdata(a_Source, i, 0);
+ LOGD("%i push usertype: %p of type '%s'", i, ud, type);
+ if( type == 0 )
+ {
+ LOGERROR("Call(): Something went wrong when trying to get usertype name!");
+ return 0;
+ }
+ tolua_pushusertype(a_Destination, ud, type);
+ }
+ break;
default: /* other values */
- LOGERROR("Unsupported value: '%s'. Can only use numbers and strings!", lua_typename(a_Source, t));
+ LOGERROR("Call(): Unsupported value: '%s'. Can only use numbers and strings!", lua_typename(a_Source, t));
return 0;
}
}
@@ -781,12 +802,14 @@ static int tolua_cPlugin_Call(lua_State* tolua_S)
int nresults = lua_gettop(targetState) - targetTop;
LOGD("num results: %i", nresults);
int ttop = lua_gettop(targetState);
- if( copy_lua_values(targetState, tolua_S, 2, ttop) == 0 ) // Start at 2 and I have no idea why xD
+ if( copy_lua_values(targetState, tolua_S, targetTop+1, ttop) == 0 ) // Start at targetTop+1 and I have no idea why xD
{
// something went wrong, exit
return 0;
}
+ lua_pop(targetState, nresults+1); // I have no idea what I'm doing, but it works
+
return nresults;
}