diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2016-04-04 09:44:12 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2016-04-04 09:44:12 +0000 |
commit | 32089106fa10eba08e946693cb2939a4ab293f77 (patch) | |
tree | 102d714e16eb4d5c8da2a6a34d497ad10724c35f /plugins/MirLua/src/mlua_metatable.h | |
parent | e1110157f8c2989a58aa12ddeef91669525d188f (diff) |
MirLua:
- no need to copy pointer data in MT
- project cleanup
- version bump
git-svn-id: http://svn.miranda-ng.org/main/trunk@16584 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src/mlua_metatable.h')
-rw-r--r-- | plugins/MirLua/src/mlua_metatable.h | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/plugins/MirLua/src/mlua_metatable.h b/plugins/MirLua/src/mlua_metatable.h index 5262b6f50c..b8fcdec22b 100644 --- a/plugins/MirLua/src/mlua_metatable.h +++ b/plugins/MirLua/src/mlua_metatable.h @@ -59,8 +59,9 @@ private: static void Init(lua_State *L, T **obj)
{
luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
- T *udata = (T*)lua_touserdata(L, 1);
- memcpy(*obj, udata, sizeof(T));
+ //T *udata = (T*)lua_touserdata(L, 1);
+ //memcpy(*obj, udata, sizeof(T));
+ *obj = (T*)lua_touserdata(L, 1);
}
static void Free(T **obj)
@@ -70,10 +71,10 @@ private: static int lua_new(lua_State *L)
{
- T *udata = (T*)lua_newuserdata(L, sizeof(T));
- memset(udata, 0, sizeof(T));
- Init(L, &udata);
- if (udata == NULL)
+ T **udata = (T**)lua_newuserdata(L, sizeof(T*));
+ //memset(udata, 0, sizeof(T));
+ Init(L, udata);
+ if (*udata == NULL)
{
lua_pushnil(L);
return 1;
@@ -83,9 +84,17 @@ private: return 1;
}
+ static int lua__call(lua_State *L)
+ {
+ T *obj = *(T**)luaL_checkudata(L, 1, MT::name);
+ lua_pushlightuserdata(L, obj);
+
+ return 1;
+ }
+
static int lua__index(lua_State *L)
{
- T *obj = (T*)luaL_checkudata(L, 1, MT::name);
+ T *obj = *(T**)luaL_checkudata(L, 1, MT::name);
const char *key = lua_tostring(L, 2);
auto it = fields.find(key);
@@ -129,8 +138,8 @@ private: static int lua__gc(lua_State *L)
{
- T *obj = (T*)luaL_checkudata(L, 1, MT::name);
- MT::Free(&obj);
+ T **obj = (T**)luaL_checkudata(L, 1, MT::name);
+ MT::Free(obj);
return 0;
}
@@ -144,6 +153,8 @@ public: luaL_newmetatable(L, MT::name);
lua_pushcfunction(L, lua__index);
lua_setfield(L, -2, "__index");
+ lua_pushcfunction(L, lua__call);
+ lua_setfield(L, -2, "__call");
lua_pushcfunction(L, lua__gc);
lua_setfield(L, -2, "__gc");
}
|