diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2016-06-05 18:08:58 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2016-06-05 18:08:58 +0000 |
commit | 8cf0298ead2e6d2930fd528ea0fc901d83208ddf (patch) | |
tree | b95b32d4a9165d9ced874bdffeb7e0ff7c0d7329 /plugins/MirLua/src/mlua_metatable.h | |
parent | e5f74a7f7b50800e9b9bb3bdf694b8886cdeb3fc (diff) |
MirLua:
- GetContactInfo changed params place
- reworked MT initialization
git-svn-id: http://svn.miranda-ng.org/main/trunk@16921 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src/mlua_metatable.h')
-rw-r--r-- | plugins/MirLua/src/mlua_metatable.h | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/plugins/MirLua/src/mlua_metatable.h b/plugins/MirLua/src/mlua_metatable.h index e67f54ee6d..fe1e2eba10 100644 --- a/plugins/MirLua/src/mlua_metatable.h +++ b/plugins/MirLua/src/mlua_metatable.h @@ -74,7 +74,7 @@ private: *obj = NULL;
}
- static int lua_new(lua_State *L)
+ static int lua__new(lua_State *L)
{
T **udata = (T**)lua_newuserdata(L, sizeof(T*));
Init(L, udata);
@@ -90,6 +90,17 @@ private: static int lua__call(lua_State *L)
{
+ int nargs = lua_gettop(L);
+ lua_pushcfunction(L, lua__new);
+ for (int i = 2; i <= nargs; i++)
+ lua_pushvalue(L, i);
+ luaM_pcall(L, nargs - 1, 1);
+
+ return 1;
+ }
+
+ static int lua__bnot(lua_State *L)
+ {
T *obj = *(T**)luaL_checkudata(L, 1, MT::name);
lua_pushlightuserdata(L, obj);
@@ -152,15 +163,24 @@ public: {
MT::name = tname;
- lua_register(L, MT::name, lua_new);
-
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__index);
+ lua_setfield(L, -2, "__index");
+ lua_pushcfunction(L, lua__bnot);
+ lua_setfield(L, -2, "__bnot");
lua_pushcfunction(L, lua__gc);
lua_setfield(L, -2, "__gc");
+ lua_pop(L, 1);
+
+ lua_createtable(L, 0, 1);
+ lua_pushcfunction(L, lua__new);
+ lua_setfield(L, -2, "new");
+ lua_pushvalue(L, -1);
+ lua_setglobal(L, MT::name);
+ luaL_setmetatable(L, MT::name);
+ lua_pop(L, 1);
}
template<typename R>
|