diff options
-rw-r--r-- | plugins/MirLua/include/mirlua.h | 2 | ||||
-rw-r--r-- | plugins/MirLua/src/m_http.cpp | 6 | ||||
-rw-r--r-- | plugins/MirLua/src/m_protocols.cpp | 2 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua.cpp | 41 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_metatable.h | 60 |
5 files changed, 49 insertions, 62 deletions
diff --git a/plugins/MirLua/include/mirlua.h b/plugins/MirLua/include/mirlua.h index 6cf96011ff..07421a482e 100644 --- a/plugins/MirLua/include/mirlua.h +++ b/plugins/MirLua/include/mirlua.h @@ -18,7 +18,7 @@ __forceinline UINT_PTR luaM_tomparam(lua_State *L, int idx) lua_Integer res = 0; lua_Number num = lua_tonumber(L, idx); if (lua_numbertointeger(num, &res)) - return res; + return (UINT_PTR)res; } } return NULL; diff --git a/plugins/MirLua/src/m_http.cpp b/plugins/MirLua/src/m_http.cpp index e1aece0e12..5d1e7d4519 100644 --- a/plugins/MirLua/src/m_http.cpp +++ b/plugins/MirLua/src/m_http.cpp @@ -294,10 +294,10 @@ static void request_SetContent(lua_State *L, int idx, NETLIBHTTPREQUEST *request static void request_SetContentType(lua_State *L, int idx, NETLIBHTTPREQUEST *request) { - if (!lua_isstring(L, 2)) + if (!lua_isstring(L, idx)) return; - const char *type = lua_tostring(L, 2); + const char *type = lua_tostring(L, idx); SetHeader(request, "Content-Type", type); } @@ -389,7 +389,7 @@ static int request__gc(lua_State *L) NETLIBHTTPREQUEST **request = (NETLIBHTTPREQUEST**)luaL_checkudata(L, 1, MT_NETLIBHTTPREQUEST); mir_free((*request)->szUrl); - for (size_t i = 0; i < (*request)->headersCount; i++) { + for (int i = 0; i < (*request)->headersCount; i++) { mir_free((*request)->headers[i].szName); mir_free((*request)->headers[i].szValue); } diff --git a/plugins/MirLua/src/m_protocols.cpp b/plugins/MirLua/src/m_protocols.cpp index f4ea022175..4ecb5d7b3c 100644 --- a/plugins/MirLua/src/m_protocols.cpp +++ b/plugins/MirLua/src/m_protocols.cpp @@ -237,7 +237,7 @@ static luaL_Reg protocolsApi[] = {
{ "GetProtocol", lua_GetProtocol },
{ "Protocols", lua_Protocols },
- { "RegisterProtocol", lua_Protocols },
+ { "RegisterProtocol", lua_RegisterProtocol },
{ "CallSendChain", lua_ChainSend },
{ "CallReceiveChain", lua_ChainRecv },
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index dba1cb607a..4b438122c6 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -27,10 +27,8 @@ static int mlua_print(lua_State *L) {
CMStringA data;
int nargs = lua_gettop(L);
- for (int i = 1; i <= nargs; i++)
- {
- switch (lua_type(L, i))
- {
+ for (int i = 1; i <= nargs; i++) {
+ switch (lua_type(L, i)) {
case LUA_TNIL:
data.Append("nil");
break;
@@ -95,11 +93,9 @@ static int mlua_topointer(lua_State *L) lua_pushlightuserdata(L, (void*)lua_toboolean(L, 1));
break;
case LUA_TNUMBER:
- if (lua_isinteger(L, 1))
- {
+ if (lua_isinteger(L, 1)) {
lua_Integer value = lua_tointeger(L, 1);
- if (value > INTPTR_MAX)
- {
+ if (value > INTPTR_MAX) {
const char *msg = lua_pushfstring(L, "%f is larger than %d", value, INTPTR_MAX);
return luaL_argerror(L, 1, msg);
}
@@ -120,8 +116,7 @@ static int mlua_topointer(lua_State *L) static int mlua_tonumber(lua_State *L)
{
- if (lua_islightuserdata(L, 1))
- {
+ if (lua_islightuserdata(L, 1)) {
lua_Integer value = (lua_Integer)lua_touserdata(L, 1);
lua_pushinteger(L, value);
return 1;
@@ -168,14 +163,11 @@ static int mlua_interpolate(lua_State *L) size_t level = 1;
- while (lua_getstack(L, level++, &ar))
- {
+ while (lua_getstack(L, level++, &ar)) {
size_t i = 1;
- while (const char *name = lua_getlocal(L, &ar, i++))
- {
+ while (const char *name = lua_getlocal(L, &ar, i++)) {
const char *val = lua_tostring(L, -1);
- if (val)
- {
+ if (val) {
mir_snprintf(pattern, "${%s}", name);
string = luaL_gsub(L, string, pattern, val);
lua_pop(L, 1);
@@ -217,7 +209,9 @@ void CMLua::Load() lua_register(L, "print", mlua_print);
lua_register(L, "a", mlua_toansi);
+ lua_register(L, "toansi", mlua_toansi);
lua_register(L, "u", mlua_toucs2);
+ lua_register(L, "toucs2", mlua_toucs2);
lua_register(L, "topointer", mlua_topointer);
lua_getglobal(L, "tonumber");
@@ -267,22 +261,18 @@ void CMLua::Unload() void CMLua::KillLuaRefs()
{
- while (HookRefs.getCount())
- {
+ while (HookRefs.getCount()) {
HandleRefParam *param = (HandleRefParam*)HookRefs[0];
- if (param != nullptr)
- {
+ if (param != nullptr) {
luaL_unref(param->L, LUA_REGISTRYINDEX, param->ref);
HookRefs.remove(0);
delete param;
}
}
- while (ServiceRefs.getCount())
- {
+ while (ServiceRefs.getCount()) {
HandleRefParam *param = (HandleRefParam*)ServiceRefs[0];
- if (param != nullptr)
- {
+ if (param != nullptr) {
luaL_unref(param->L, LUA_REGISTRYINDEX, param->ref);
ServiceRefs.remove(0);
delete param;
@@ -297,8 +287,7 @@ static int mlua_call(lua_State *L) const char *module = luaL_checkstring(L, -3);
const char *function = luaL_checkstring(L, -2);
- if (module && module[0])
- {
+ if (module && module[0]) {
lua_getglobal(L, "require");
lua_pushstring(L, module);
lua_pcall(L, 1, 1, 0);
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_
|