summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2016-02-01 12:58:04 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2016-02-01 12:58:04 +0000
commit014e23323d6dc79605da8ebad1c357176ede9122 (patch)
tree783042c8aba1d71645028720bac8f8f70eca3b54 /plugins
parente1b171840899382e773c89b21e0510e9eddd95b0 (diff)
MirLua: Code cleanup
git-svn-id: http://svn.miranda-ng.org/main/trunk@16206 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/MirLua/src/m_database.cpp9
-rw-r--r--plugins/MirLua/src/mlua_metatable.h4
-rw-r--r--plugins/MirLua/src/stdafx.h8
3 files changed, 13 insertions, 8 deletions
diff --git a/plugins/MirLua/src/m_database.cpp b/plugins/MirLua/src/m_database.cpp
index a8cb78f435..82d4fe6aeb 100644
--- a/plugins/MirLua/src/m_database.cpp
+++ b/plugins/MirLua/src/m_database.cpp
@@ -182,8 +182,7 @@ static int array__call(lua_State *L)
BLOB *blob = (BLOB*)lua_newuserdata(L, sizeof(BLOB));
blob->cbSize = size;
- blob->pBlobData = (BYTE*)mir_alloc(sizeof(BYTE) * blob->cbSize);
- memcpy(blob->pBlobData, udata, sizeof(BYTE)* blob->cbSize);
+ blob->pBlobData = mir_memdup(udata, size);
luaL_setmetatable(L, MT_BLOB);
return 1;
@@ -291,8 +290,7 @@ static int lua_GetSetting(lua_State *L)
{
BLOB *blob = (BLOB*)lua_newuserdata(L, sizeof(BLOB));
blob->cbSize = dbv.cpbVal;
- blob->pBlobData = (BYTE*)mir_alloc(sizeof(BYTE) * blob->cbSize);
- memcpy(blob->pBlobData, dbv.pbVal, sizeof(BYTE) * blob->cbSize);
+ blob->pBlobData = mir_memdup(dbv.pbVal, dbv.cpbVal);
luaL_setmetatable(L, MT_BLOB);
}
break;
@@ -542,8 +540,7 @@ static int dbcw__index(lua_State *L)
{
BLOB *blob = (BLOB*)lua_newuserdata(L, sizeof(BLOB));
blob->cbSize = dbcw->value.cpbVal;
- blob->pBlobData = (BYTE*)mir_alloc(sizeof(BYTE) * blob->cbSize);
- memcpy(blob->pBlobData, dbcw->value.pbVal, sizeof(BYTE) * blob->cbSize);
+ blob->pBlobData = mir_memdup(dbcw->value.pbVal, blob->cbSize);
luaL_setmetatable(L, MT_BLOB);
}
break;
diff --git a/plugins/MirLua/src/mlua_metatable.h b/plugins/MirLua/src/mlua_metatable.h
index 372f8684a3..ec5ee58451 100644
--- a/plugins/MirLua/src/mlua_metatable.h
+++ b/plugins/MirLua/src/mlua_metatable.h
@@ -111,7 +111,7 @@ private:
lua_pushstring(L, ptrA(mir_utf8encode(field->GetValue<char*>(obj))));
break;
case LUA_TSTRINGW:
- lua_pushstring(L, ptrA(mir_utf8encodeW(field->GetValue<wchar_t*>(obj))));
+ lua_pushstring(L, T2Utf(field->GetValue<wchar_t*>(obj)));
break;
case LUA_TLIGHTUSERDATA:
lua_pushlightuserdata(L, field->GetValue<void*>(obj));
@@ -150,7 +150,7 @@ public:
template<typename R>
MT& Field(R T::*M, const char *name, int type, size_t size = sizeof(R))
{
- size_t offset = reinterpret_cast<size_t>(&(((T*)0)->*M));
+ size_t offset = offsetof(T, *M);
if (type != LUA_TNONE)
fields[name] = new MTField<T>(offset, size, type);
return *this;
diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h
index efefd020ad..90e60660d8 100644
--- a/plugins/MirLua/src/stdafx.h
+++ b/plugins/MirLua/src/stdafx.h
@@ -47,6 +47,14 @@ struct luaM_const
intptr_t value;
};
+template<typename T>
+T *mir_memdup(T* ptr, size_t size = sizeof(T), bool bCalloc = false)
+{
+ void *newptr = (bCalloc ? mir_calloc : mir_alloc)(size);
+ memcpy(newptr, ptr, size);
+ return (T*)newptr;
+}
+
#include "mlua.h"
#include "mlua_script.h"
#include "mlua_module_loader.h"