diff options
author | aunsane <aunsane@gmail.com> | 2018-03-19 21:37:26 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2018-03-19 21:37:48 +0300 |
commit | 165d7791631a9c9ed0998c90b696116593ebfd70 (patch) | |
tree | 8d42ce79b67eb1797e6242e096e1919e508ac0c1 /plugins/MirLua/src/mlua_metatable.h | |
parent | 81781c336c74447c4d64b367b958b2c7835f7271 (diff) |
MirLua:
- new functions toansi & toucs2
- warning fixes
Diffstat (limited to 'plugins/MirLua/src/mlua_metatable.h')
-rw-r--r-- | plugins/MirLua/src/mlua_metatable.h | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/plugins/MirLua/src/mlua_metatable.h b/plugins/MirLua/src/mlua_metatable.h index c46d397dbb..6de588edf8 100644 --- a/plugins/MirLua/src/mlua_metatable.h +++ b/plugins/MirLua/src/mlua_metatable.h @@ -30,8 +30,6 @@ public: CMTField(const char *name, int type) :
name(mir_strdup(name)), type(type) {}
- virtual ~CMTField() {};
-
const char* GetName() const { return name; }
int GetType() const { return type; }
@@ -54,7 +52,7 @@ public: virtual MTValue GetValue(void *obj)
{
- MTValue value = { };
+ MTValue value = {};
memcpy(&value, ((char*)obj + offset), sizeof(R));
return value;
}
@@ -70,7 +68,7 @@ public: virtual MTValue GetValue(void*)
{
- MTValue value = { };
+ MTValue value = {};
value.function = function;
return value;
}
@@ -97,9 +95,9 @@ class MT private:
lua_State *L;
- static const char *name;
- static const luaL_Reg events[];
- static OBJLIST<CMTField> fields;
+ static const char *Name;
+ static const luaL_Reg Events[];
+ static OBJLIST<CMTField> Fields;
static T* Init(lua_State *L)
{
@@ -113,7 +111,7 @@ private: return 1;
}
- static bool Set(lua_State *L, T* /*obj*/)
+ static bool Set(lua_State* /*L*/, T* /*obj*/)
{
return false;
}
@@ -134,22 +132,22 @@ private: return 1;
}
- luaL_setmetatable(L, MT::name);
+ luaL_setmetatable(L, Name);
return 1;
}
static int lua__gc(lua_State *L)
{
- T **obj = (T**)luaL_checkudata(L, 1, MT::name);
- MT::Free(L, obj);
+ T **obj = (T**)luaL_checkudata(L, 1, Name);
+ Free(L, obj);
return 0;
}
static int lua__bnot(lua_State *L)
{
- T *obj = *(T**)luaL_checkudata(L, 1, MT::name);
+ T *obj = *(T**)luaL_checkudata(L, 1, Name);
lua_pushlightuserdata(L, obj);
return 1;
@@ -157,11 +155,11 @@ private: static int lua__index(lua_State *L)
{
- T *obj = *(T**)luaL_checkudata(L, 1, MT::name);
+ T *obj = *(T**)luaL_checkudata(L, 1, Name);
const char *key = lua_tostring(L, 2);
const void *tmp[2] = { nullptr, key };
- CMTField *field = fields.find((CMTField*)&tmp);
+ CMTField *field = Fields.find((CMTField*)&tmp);
if (field == nullptr)
return Get(L, obj);
@@ -201,11 +199,11 @@ private: static int lua__newindex(lua_State *L)
{
- T *obj = *(T**)luaL_checkudata(L, 1, MT::name);
+ T *obj = *(T**)luaL_checkudata(L, 1, Name);
if (!Set(L, obj)) {
const char *key = lua_tostring(L, 2);
- luaL_error(L, "attempt to index a %s value (%s is readonly)", MT::name, key);
+ luaL_error(L, "attempt to index a %s value (%s is readonly)", Name, key);
}
return 0;
@@ -213,11 +211,11 @@ private: static int lua__tostring(lua_State *L)
{
- T *obj = *(T**)luaL_checkudata(L, 1, MT::name);
- CMStringA data(MT::name);
+ T *obj = *(T**)luaL_checkudata(L, 1, Name);
+ CMStringA data(Name);
data += "(";
- for (auto &it : fields) {
+ for (auto &it : Fields) {
data += it->GetName();
data += "=";
@@ -272,13 +270,13 @@ private: }
public:
- MT(lua_State *L, const char *tname)
+ MT(lua_State *L, const char *name)
: L(L)
{
- MT::name = tname;
+ Name = name;
- luaL_newmetatable(L, MT::name);
- luaL_setfuncs(L, events, 0);
+ luaL_newmetatable(L, Name);
+ luaL_setfuncs(L, Events, 0);
lua_pop(L, 1);
lua_createtable(L, 0, 1);
@@ -289,7 +287,7 @@ public: lua_pushcfunction(L, lua__call);
lua_setfield(L, -2, "__call");
lua_setmetatable(L, -2);
- lua_setglobal(L, MT::name);
+ lua_setglobal(L, Name);
}
template<typename R>
@@ -299,7 +297,7 @@ public: size = sizeof(M);
size_t offset = (size_t)(&(((T*)0)->*M));
if (type != LUA_TNONE)
- fields.insert(new CMTFieldOffset<R>(name, type, offset, size));
+ Fields.insert(new CMTFieldOffset<R>(name, type, offset, size));
return *this;
}
@@ -307,13 +305,13 @@ public: MT& Field(const L &lambda, const char *name, int type)
{
if (type != LUA_TNONE)
- fields.insert(new CMTFieldLambda<T>(name, type, lambda));
+ Fields.insert(new CMTFieldLambda<T>(name, type, lambda));
return *this;
}
MT& Field(const lua_CFunction function, const char *name)
{
- fields.insert(new CMTFieldFunction(name, function));
+ Fields.insert(new CMTFieldFunction(name, function));
return *this;
}
@@ -326,15 +324,15 @@ public: T **udata = (T**)lua_newuserdata(L, sizeof(T));
*udata = obj;
- luaL_setmetatable(L, MT::name);
+ luaL_setmetatable(L, Name);
}
};
template<typename T>
-const char *MT<T>::name;
+const char *MT<T>::Name;
template<typename T>
-const luaL_Reg MT<T>::events[] = {
+const luaL_Reg MT<T>::Events[] = {
{ "__index", lua__index },
{ "__newindex", lua__newindex },
{ "__bnot", lua__bnot },
@@ -345,6 +343,6 @@ const luaL_Reg MT<T>::events[] = { };
template<typename T>
-OBJLIST<CMTField> MT<T>::fields(5, &CMTField::Compare);
+OBJLIST<CMTField> MT<T>::Fields(5, &CMTField::Compare);
#endif //_LUA_METATABLE_H_
|