diff options
-rw-r--r-- | plugins/MirLua/MirLua.vcxproj | 2 | ||||
-rw-r--r-- | plugins/MirLua/src/m_chat.cpp | 147 | ||||
-rw-r--r-- | plugins/MirLua/src/m_database.cpp | 34 | ||||
-rw-r--r-- | plugins/MirLua/src/m_message.cpp | 2 | ||||
-rw-r--r-- | plugins/MirLua/src/m_msg_buttonsbar.cpp | 2 | ||||
-rw-r--r-- | plugins/MirLua/src/m_protocols.cpp | 27 | ||||
-rw-r--r-- | plugins/MirLua/src/main.cpp | 2 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_metatable.h | 38 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_module_loader.cpp | 1 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_options.cpp | 30 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_options.h | 6 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_script.cpp | 33 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_script.h | 3 | ||||
-rw-r--r-- | plugins/MirLua/src/stdafx.h | 30 |
14 files changed, 95 insertions, 262 deletions
diff --git a/plugins/MirLua/MirLua.vcxproj b/plugins/MirLua/MirLua.vcxproj index 25c631aaf3..2df46203b7 100644 --- a/plugins/MirLua/MirLua.vcxproj +++ b/plugins/MirLua/MirLua.vcxproj @@ -40,4 +40,4 @@ <ItemGroup>
<None Include="res\*.ico" />
</ItemGroup>
-</Project>
\ No newline at end of file +</Project>
diff --git a/plugins/MirLua/src/m_chat.cpp b/plugins/MirLua/src/m_chat.cpp index e6938a8c94..7619fab7d6 100644 --- a/plugins/MirLua/src/m_chat.cpp +++ b/plugins/MirLua/src/m_chat.cpp @@ -1,141 +1,7 @@ #include "stdafx.h"
-int GCHookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM param)
-{
- lua_State *L = (lua_State*)obj;
-
- int ref = param;
- lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
-
- WPARAM* wParam_ptr = (WPARAM*)lua_newuserdata(L, sizeof(WPARAM));
- *wParam_ptr = wParam;
-
- LPARAM* lParam_ptr = (LPARAM*)lua_newuserdata(L, sizeof(LPARAM));
- *lParam_ptr = lParam;
-
- GCEVENT *gce = (GCEVENT*)lParam;
-
- lua_newtable(L);
- lua_pushliteral(L, "Module");
- lua_pushstring(L, gce->pDest->pszModule);
- lua_settable(L, -3);
- lua_pushliteral(L, "Id");
- lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID)));
- lua_settable(L, -3);
- lua_pushliteral(L, "Type");
- lua_pushinteger(L, gce->pDest->iType);
- lua_settable(L, -3);
- lua_pushliteral(L, "Timestamp");
- lua_pushnumber(L, gce->time);
- lua_settable(L, -3);
- lua_pushliteral(L, "IsMe");
- lua_pushboolean(L, gce->bIsMe);
- lua_settable(L, -3);
- lua_pushliteral(L, "Flags");
- lua_pushinteger(L, gce->dwFlags);
- lua_settable(L, -3);
- lua_pushliteral(L, "Uid");
- lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID)));
- lua_settable(L, -3);
- lua_pushliteral(L, "Nick");
- lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID)));
- lua_settable(L, -3);
- lua_pushliteral(L, "Status");
- lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID)));
- lua_settable(L, -3);
- lua_pushliteral(L, "Text");
- lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID)));
- lua_settable(L, -3);
-
- luaM_pcall(L, 2, 1);
-
- int res = (int)lua_tointeger(L, 1);
-
- return res;
-}
-
-static int lua_OnReceiveEvent(lua_State *L)
-{
- ObsoleteMethod(L, "Use m.HookEvent instead");
-
- if (!lua_isfunction(L, 1))
- {
- lua_pushlightuserdata(L, NULL);
- return 1;
- }
-
- lua_pushvalue(L, 1);
- int ref = luaL_ref(L, LUA_REGISTRYINDEX);
-
- HANDLE res = ::HookEventObjParam(ME_GC_HOOK_EVENT, GCHookEventObjParam, L, ref);
- lua_pushlightuserdata(L, res);
-
- CMLua::HookRefs.insert(new HandleRefParam(L, res, ref));
-
- return 1;
-}
-
static luaL_Reg chatApi[] =
{
- { "OnReceiveEvent", lua_OnReceiveEvent },
-
- { NULL, NULL }
-};
-
-#define MT_GCEVENT "GCEVENT"
-
-static int gce__init(lua_State *L)
-{
- GCEVENT *udata = (GCEVENT*)lua_touserdata(L, 1);
- if (udata == NULL)
- {
- lua_pushnil(L);
- return 1;
- }
-
- GCEVENT **gce = (GCEVENT**)lua_newuserdata(L, sizeof(GCEVENT*));
- *gce = udata;
-
- luaL_setmetatable(L, MT_GCEVENT);
-
- return 1;
-}
-
-static int gce__index(lua_State *L)
-{
- GCEVENT *gce = (GCEVENT*)luaL_checkudata(L, 1, MT_GCEVENT);
- const char *key = luaL_checkstring(L, 2);
-
- if (mir_strcmpi(key, "Module") == 0)
- lua_pushstring(L, gce->pDest->pszModule);
- else if (mir_strcmpi(key, "Id") == 0)
- lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID)));
- else if (mir_strcmpi(key, "Type") == 0)
- lua_pushinteger(L, gce->pDest->iType);
- else if (mir_strcmpi(key, "Timestamp") == 0)
- lua_pushnumber(L, gce->time);
- else if (mir_strcmpi(key, "IsMe") == 0)
- lua_pushboolean(L, gce->bIsMe);
- else if (mir_strcmpi(key, "Flags") == 0)
- lua_pushinteger(L, gce->dwFlags);
- else if (mir_strcmpi(key, "Uid") == 0)
- lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID)));
- else if (mir_strcmpi(key, "Nick") == 0)
- lua_pushstring(L, ptrA(mir_utf8encodeT(gce->ptszNick)));
- else if (mir_strcmpi(key, "Status") == 0)
- lua_pushstring(L, ptrA(mir_utf8encodeT(gce->ptszStatus)));
- else if (mir_strcmpi(key, "Text") == 0)
- lua_pushstring(L, ptrA(mir_utf8encodeT(gce->ptszText)));
- else
- lua_pushnil(L);
-
- return 1;
-}
-
-static const luaL_Reg gceMeta[] =
-{
- { "__init", gce__init },
- { "__index", gce__index },
{ NULL, NULL }
};
@@ -143,8 +9,17 @@ LUAMOD_API int luaopen_m_chat(lua_State *L) {
luaL_newlib(L, chatApi);
- luaL_newmetatable(L, MT_GCEVENT);
- luaL_setfuncs(L, gceMeta, 0);
+ MT<GCEVENT>(L, "GCEVENT")
+ .Field([](GCEVENT *gce) { return (void*)gce->pDest->pszModule; }, "Module", LUA_TSTRINGA)
+ .Field([](GCEVENT *gce) { return (void*)gce->pDest->ptszID; }, "Id", LUA_TSTRINGW)
+ .Field([](GCEVENT *gce) { return (void*)gce->pDest->iType; }, "Type", LUA_TINTEGER)
+ .Field(&GCEVENT::time, "Timestamp", LUA_TINTEGER)
+ .Field(&GCEVENT::time, "IsMe", LUA_TINTEGER)
+ .Field(&GCEVENT::time, "Flags", LUA_TINTEGER)
+ .Field(&GCEVENT::ptszNick, "Nick", LUA_TSTRINGW)
+ .Field(&GCEVENT::ptszUID, "Uid", LUA_TSTRINGW)
+ .Field(&GCEVENT::ptszStatus, "Status", LUA_TSTRINGW)
+ .Field(&GCEVENT::ptszText, "Text", LUA_TSTRINGW);
lua_pop(L, 1);
return 1;
diff --git a/plugins/MirLua/src/m_database.cpp b/plugins/MirLua/src/m_database.cpp index 82d4fe6aeb..b7d05e220b 100644 --- a/plugins/MirLua/src/m_database.cpp +++ b/plugins/MirLua/src/m_database.cpp @@ -177,12 +177,13 @@ static int lua_EventsFromEnd(lua_State *L) static int array__call(lua_State *L)
{
- BYTE *udata = (BYTE *)luaL_opt(L, lua_touserdata, 1, NULL);
+ BYTE *data = (BYTE*)lua_touserdata(L, 1);
size_t size = luaL_checkinteger(L, 2);
- BLOB *blob = (BLOB*)lua_newuserdata(L, sizeof(BLOB));
+ BLOB *blob = (BLOB*)lua_newuserdata(L, sizeof(BLOB*));
blob->cbSize = size;
- blob->pBlobData = mir_memdup(udata, size);
+ blob->pBlobData = (BYTE*)mir_calloc(size);
+ memcpy(blob->pBlobData, data, size);
luaL_setmetatable(L, MT_BLOB);
return 1;
@@ -191,9 +192,9 @@ static int array__call(lua_State *L) static int array__index(lua_State *L)
{
BLOB *blob = (BLOB*)luaL_checkudata(L, 1, MT_BLOB);
- int idx = luaL_checkinteger(L, 2);
+ int i = luaL_checkinteger(L, 2);
- lua_pushinteger(L, (uint8_t)blob->pBlobData[idx - 1]);
+ lua_pushinteger(L, (uint8_t)blob->pBlobData[i - 1]);
return 1;
}
@@ -201,10 +202,9 @@ static int array__index(lua_State *L) static int array__newindex(lua_State *L)
{
BLOB *blob = (BLOB*)luaL_checkudata(L, 1, MT_BLOB);
- int idx = luaL_checkinteger(L, 2);
- uint8_t val = (uint8_t)luaL_checkinteger(L, 3);
+ int i = luaL_checkinteger(L, 2);
- blob->pBlobData[idx - 1] = val;
+ blob->pBlobData[i - 1] = (BYTE)luaL_checkinteger(L, 3);
return 0;
}
@@ -288,10 +288,11 @@ static int lua_GetSetting(lua_State *L) break;
case DBVT_BLOB:
{
- BLOB *blob = (BLOB*)lua_newuserdata(L, sizeof(BLOB));
- blob->cbSize = dbv.cpbVal;
- blob->pBlobData = mir_memdup(dbv.pbVal, dbv.cpbVal);
- luaL_setmetatable(L, MT_BLOB);
+ luaL_getmetatable(L, MT_BLOB);
+ lua_getfield(L, -1, "__call");
+ lua_pushlightuserdata(L, dbv.pbVal);
+ lua_pushnumber(L, dbv.cpbVal);
+ luaM_pcall(L, 2, 1);
}
break;
default:
@@ -538,10 +539,11 @@ static int dbcw__index(lua_State *L) break;
case DBVT_BLOB:
{
- BLOB *blob = (BLOB*)lua_newuserdata(L, sizeof(BLOB));
- blob->cbSize = dbcw->value.cpbVal;
- blob->pBlobData = mir_memdup(dbcw->value.pbVal, blob->cbSize);
- luaL_setmetatable(L, MT_BLOB);
+ luaL_getmetatable(L, MT_BLOB);
+ lua_getfield(L, -1, "__call");
+ lua_pushlightuserdata(L, dbcw->value.pbVal);
+ lua_pushnumber(L, dbcw->value.cpbVal);
+ luaM_pcall(L, 2, 1);
}
break;
default:
diff --git a/plugins/MirLua/src/m_message.cpp b/plugins/MirLua/src/m_message.cpp index 444963f640..64025eb132 100644 --- a/plugins/MirLua/src/m_message.cpp +++ b/plugins/MirLua/src/m_message.cpp @@ -85,7 +85,7 @@ LUAMOD_API int luaopen_m_message(lua_State *L) .Field(&MessageWindowEventData::uType, "Type", LUA_TINTEGER)
.Field(&MessageWindowEventData::hContact, "hContact", LUA_TINTEGER)
.Field(&MessageWindowEventData::uFlags, "Flags", LUA_TINTEGER);
- lua_pop(L, 1);
+ lua_pop(L, 1);
return 1;
}
diff --git a/plugins/MirLua/src/m_msg_buttonsbar.cpp b/plugins/MirLua/src/m_msg_buttonsbar.cpp index 39fff188a1..c960e6dc69 100644 --- a/plugins/MirLua/src/m_msg_buttonsbar.cpp +++ b/plugins/MirLua/src/m_msg_buttonsbar.cpp @@ -137,7 +137,7 @@ LUAMOD_API int luaopen_m_msg_buttonsbar(lua_State *L) .Field(&CustomButtonClickData::dwButtonId, "ButtonID", LUA_TINTEGER)
.Field(&CustomButtonClickData::hContact, "hContact", LUA_TINTEGER)
.Field(&CustomButtonClickData::flags, "Flags", LUA_TINTEGER);
- lua_pop(L, 1);
+ lua_pop(L, 1);
return 1;
}
diff --git a/plugins/MirLua/src/m_protocols.cpp b/plugins/MirLua/src/m_protocols.cpp index 2f6f5af836..5e30c1dad4 100644 --- a/plugins/MirLua/src/m_protocols.cpp +++ b/plugins/MirLua/src/m_protocols.cpp @@ -152,28 +152,6 @@ static luaL_Reg protocolsApi[] = /***********************************************/
-#define MT_CCSDATA "CCSDATA"
-
-static int ccs__index(lua_State *L)
-{
- CCSDATA *ccs = *(CCSDATA**)luaL_checkudata(L, 1, MT_CCSDATA);
- const char *key = lua_tostring(L, 2);
-
- if (mir_strcmpi(key, "hContact") == 0)
- lua_pushinteger(L, ccs->hContact);
- else if (mir_strcmpi(key, "Message") == 0)
- {
- PROTORECVEVENT *pre = (PROTORECVEVENT*)ccs->lParam;
- lua_pushstring(L, pre->szMessage);
- }
- else
- lua_pushnil(L);
-
- return 1;
-}
-
-/***********************************************/
-
LUAMOD_API int luaopen_m_protocols(lua_State *L)
{
luaL_newlib(L, protocolsApi);
@@ -202,8 +180,9 @@ LUAMOD_API int luaopen_m_protocols(lua_State *L) .Field(&ACKDATA::lParam, "lParam", LUA_TLIGHTUSERDATA);
lua_pop(L, 1);
- MT<CCSDATA>(L, MT_CCSDATA)
- .Method(ccs__index, "__index");
+ MT<CCSDATA>(L, "CCSDATA")
+ .Field(&CCSDATA::hContact, "hContact", LUA_TINTEGER)
+ .Field([](CCSDATA *ccs) { return ((PROTORECVEVENT*)ccs->lParam)->szMessage; }, "Message", LUA_TSTRING);
lua_pop(L, 1);
return 1;
diff --git a/plugins/MirLua/src/main.cpp b/plugins/MirLua/src/main.cpp index 3e560d91cb..973a681a15 100644 --- a/plugins/MirLua/src/main.cpp +++ b/plugins/MirLua/src/main.cpp @@ -44,7 +44,7 @@ int OnModulesLoaded(WPARAM, LPARAM) g_hCLibsFolder = FoldersRegisterCustomPathT(MODULE, "CLibsFolder", MIRLUA_PATHT, TranslateT("C libs folder"));
g_hScriptsFolder = FoldersRegisterCustomPathT(MODULE, "ScriptsFolder", MIRLUA_PATHT, TranslateT("Scripts folder"));
- HookEvent(ME_OPT_INITIALISE, CLuaOptions::OnOptionsInit);
+ HookEvent(ME_OPT_INITIALISE, CMLuaOptions::OnOptionsInit);
hRecvMessage = CreateHookableEvent(MODULE PSR_MESSAGE);
CreateProtoServiceFunction(MODULE, PSR_MESSAGE, FilterRecvMessage);
diff --git a/plugins/MirLua/src/mlua_metatable.h b/plugins/MirLua/src/mlua_metatable.h index bef297905e..143c3a6ace 100644 --- a/plugins/MirLua/src/mlua_metatable.h +++ b/plugins/MirLua/src/mlua_metatable.h @@ -9,34 +9,38 @@ #define LUA_TSTRINGA LUA_NUMTAGS + 2
#define LUA_TSTRINGW LUA_NUMTAGS + 3
-enum MTFieldGetType
-{
- MTFGT_LAMBDA = 1,
- MTFGT_OFFSET = 2
-};
-
template<typename T>
-struct MTField : public MZeroedObject
+class MTField : public MZeroedObject
{
+private:
+ enum MTFieldGetter
+ {
+ MTFG_LAMBDA = 1,
+ MTFG_OFFSET = 2
+ };
+
size_t offset;
- size_t size;
int type;
int getType;
std::function<void*(T*)> lambda;
- MTField(size_t offset, size_t size, int type)
- : offset(offset), size(size), type(type), getType(MTFGT_OFFSET) { }
+public:
+ MTField(size_t offset, int type)
+ : offset(offset), type(type), getType(MTFG_OFFSET) { }
MTField(std::function<void*(T*)> f, int type)
- : lambda(f), type(type), getType(MTFGT_LAMBDA) { }
+ : lambda(f), type(type), getType(MTFG_LAMBDA) { }
+
+ int GetType() const { return type; }
template<typename R>
R GetValue(T *obj) const
{
- if (getType == MTFGT_LAMBDA) return (R)lambda(obj);
+ if (getType == MTFG_LAMBDA) return (R)lambda(obj);
else
{
R res = NULL;
+ size_t size = sizeof(R);
memcpy(&res, ((char*)obj) + offset, size);
return res;
}
@@ -93,7 +97,7 @@ private: MTField<T> *field = it->second;
- switch (field->type)
+ switch (field->GetType())
{
case LUA_TBOOLEAN:
lua_pushboolean(L, field->GetValue<BOOL>(obj));
@@ -147,16 +151,16 @@ public: }
template<typename R>
- MT& Field(R T::*M, const char *name, int type, size_t size = sizeof(R))
+ MT& Field(R T::*M, const char *name, int type)
{
size_t offset = offsetof(T, *M);
if (type != LUA_TNONE)
- fields[name] = new MTField<T>(offset, size, type);
+ fields[name] = new MTField<T>(offset, type);
return *this;
}
- template<typename R>
- MT& Field(std::function<R(T*)> f, const char *name, int type)
+ template<typename L>
+ MT& Field(L &f, const char *name, int type)
{
if (type != LUA_TNONE)
fields[name] = new MTField<T>(f, type);
diff --git a/plugins/MirLua/src/mlua_module_loader.cpp b/plugins/MirLua/src/mlua_module_loader.cpp index 063d554367..1abe63cc51 100644 --- a/plugins/MirLua/src/mlua_module_loader.cpp +++ b/plugins/MirLua/src/mlua_module_loader.cpp @@ -27,6 +27,7 @@ void CLuaModuleLoader::LoadModules() // load m_core module
Load(MLUA_CORE, luaopen_m_core);
// load all internal modules
+ Preload(MLUA_CHAT, luaopen_m_chat);
Preload(MLUA_CLIST, luaopen_m_clist);
Preload(MLUA_DATABASE, luaopen_m_database);
Preload(MLUA_ICOLIB, luaopen_m_icolib);
diff --git a/plugins/MirLua/src/mlua_options.cpp b/plugins/MirLua/src/mlua_options.cpp index 2303e6ece3..e7f3ef729f 100644 --- a/plugins/MirLua/src/mlua_options.cpp +++ b/plugins/MirLua/src/mlua_options.cpp @@ -18,7 +18,7 @@ BOOL CCtrlScriptList::OnNotify(int idCtrl, NMHDR *pnmh) /****************************************/
-CLuaOptions::CLuaOptions(int idDialog)
+CMLuaOptions::CMLuaOptions(int idDialog)
: CDlgBase(g_hInstance, idDialog),
m_popupOnError(this, IDC_POPUPONERROR),
m_popupOnObsolete(this, IDC_POPUPONOBSOLETE),
@@ -28,40 +28,40 @@ CLuaOptions::CLuaOptions(int idDialog) CreateLink(m_popupOnError, "PopupOnError", DBVT_BYTE, 1);
CreateLink(m_popupOnObsolete, "PopupOnObsolete", DBVT_BYTE, 1);
- m_scripts.OnClick = Callback(this, &CLuaOptions::OnScriptListClick);
- m_reload.OnClick = Callback(this, &CLuaOptions::OnReload);
+ m_scripts.OnClick = Callback(this, &CMLuaOptions::OnScriptListClick);
+ m_reload.OnClick = Callback(this, &CMLuaOptions::OnReload);
}
-void CLuaOptions::CreateLink(CCtrlData& ctrl, const char *szSetting, BYTE type, DWORD iValue)
+void CMLuaOptions::CreateLink(CCtrlData& ctrl, const char *szSetting, BYTE type, DWORD iValue)
{
ctrl.CreateDbLink(MODULE, szSetting, type, iValue);
}
-void CLuaOptions::CreateLink(CCtrlData& ctrl, const char *szSetting, TCHAR *szValue)
+void CMLuaOptions::CreateLink(CCtrlData& ctrl, const char *szSetting, TCHAR *szValue)
{
ctrl.CreateDbLink(MODULE, szSetting, szValue);
}
-int CLuaOptions::OnOptionsInit(WPARAM wParam, LPARAM)
+int CMLuaOptions::OnOptionsInit(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = { 0 };
odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR | ODPF_DONTTRANSLATE;
odp.ptszGroup = LPGENT("Services");
odp.ptszTitle = _T(MODULE);
odp.ptszTab = LPGENT("Scripts");
- odp.pDialog = CLuaOptions::CreateOptionsPage();
+ odp.pDialog = CMLuaOptions::CreateOptionsPage();
Options_AddPage(wParam, &odp);
return 0;
}
-void CLuaOptions::LoadScripts()
+void CMLuaOptions::LoadScripts()
{
for (int i = 0; i < g_mLua->Scripts.getCount(); i++)
{
CMLuaScript *script = g_mLua->Scripts[i];
TCHAR *fileName = NEWTSTR_ALLOCA(script->GetFileName());
- int iIcon = script->GetStatus() == CMLuaScript::Loaded ? 0 : 1;
+ int iIcon = script->GetStatus() - 1;
int iItem = m_scripts.AddItem(fileName, iIcon, (LPARAM)script);
if (db_get_b(NULL, MODULE, _T2A(fileName), 1))
m_scripts.SetCheckState(iItem, TRUE);
@@ -70,7 +70,7 @@ void CLuaOptions::LoadScripts() }
}
-void CLuaOptions::OnInitDialog()
+void CMLuaOptions::OnInitDialog()
{
CDlgBase::OnInitDialog();
@@ -96,7 +96,7 @@ void CLuaOptions::OnInitDialog() isScriptListInit = true;
}
-void CLuaOptions::OnApply()
+void CMLuaOptions::OnApply()
{
int count = m_scripts.GetItemCount();
for (int iItem = 0; iItem < count; iItem++)
@@ -110,7 +110,7 @@ void CLuaOptions::OnApply() }
}
-INT_PTR CLuaOptions::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
+INT_PTR CMLuaOptions::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
@@ -133,7 +133,7 @@ INT_PTR CLuaOptions::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) return CDlgBase::DlgProc(msg, wParam, lParam);
}
-void CLuaOptions::OnScriptListClick(CCtrlListView::TEventInfo *evt)
+void CMLuaOptions::OnScriptListClick(CCtrlListView::TEventInfo *evt)
{
LVITEM lvi = { 0 };
lvi.iItem = evt->nmlvia->iItem;
@@ -158,7 +158,7 @@ void CLuaOptions::OnScriptListClick(CCtrlListView::TEventInfo *evt) script->Load();
lvi.mask = LVIF_IMAGE;
lvi.iSubItem = 0;
- lvi.iImage = script->GetStatus() == CMLuaScript::Loaded ? 0 : 1;
+ lvi.iImage = script->GetStatus() - 1;
ListView_SetItem(m_scripts.GetHwnd(), &lvi);
m_scripts.Update(evt->nmlvia->iItem);
break;
@@ -167,7 +167,7 @@ void CLuaOptions::OnScriptListClick(CCtrlListView::TEventInfo *evt) mir_free(lvi.pszText);
}
-void CLuaOptions::OnReload(CCtrlBase*)
+void CMLuaOptions::OnReload(CCtrlBase*)
{
isScriptListInit = false;
m_scripts.DeleteAllItems();
diff --git a/plugins/MirLua/src/mlua_options.h b/plugins/MirLua/src/mlua_options.h index b81676bfc8..cc4171938f 100644 --- a/plugins/MirLua/src/mlua_options.h +++ b/plugins/MirLua/src/mlua_options.h @@ -16,7 +16,7 @@ public: };
-class CLuaOptions : public CDlgBase
+class CMLuaOptions : public CDlgBase
{
private:
CCtrlCheck m_popupOnError;
@@ -38,7 +38,7 @@ protected: INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam);
public:
- CLuaOptions(int idDialog);
+ CMLuaOptions(int idDialog);
void CreateLink(CCtrlData& ctrl, const char *szSetting, BYTE type, DWORD iValue);
void CreateLink(CCtrlData& ctrl, const char *szSetting, TCHAR *szValue);
@@ -51,7 +51,7 @@ public: ctrl.CreateDbLink(new CMOptionLink<T>(option));
}
- static CDlgBase *CreateOptionsPage() { return new CLuaOptions(IDD_OPTIONS); }
+ static CDlgBase *CreateOptionsPage() { return new CMLuaOptions(IDD_OPTIONS); }
};
#endif //_LUA_OPTIONS_H_
\ No newline at end of file diff --git a/plugins/MirLua/src/mlua_script.cpp b/plugins/MirLua/src/mlua_script.cpp index 6a51046a94..f9fb1ac6f3 100644 --- a/plugins/MirLua/src/mlua_script.cpp +++ b/plugins/MirLua/src/mlua_script.cpp @@ -26,35 +26,32 @@ CMLuaScript::~CMLuaScript() mir_free(moduleName);
}
-/*const int CMLuaScript::GetId() const
+bool CMLuaScript::GetScriptEnviroment(lua_State *L, int n)
{
- return id;
-}*/
-
-CMLuaScript* CMLuaScript::GetScriptFromEnviroment(lua_State *L, int n)
-{
- CMLuaScript *script = NULL;
-
- int top = lua_gettop(L);
-
lua_Debug ar; if (lua_getstack(L, 1, &ar) == 0 || lua_getinfo(L, "f", &ar) == 0 || lua_iscfunction(L, -1)) { - top = lua_gettop(L); lua_pop(L, 1); - return script;
+ return false;
}
const char *env = lua_getupvalue(L, n, 1); if (!env || mir_strcmp(env, "_ENV") != 0) { - top = lua_gettop(L); lua_pop(L, 1); - return script; - } + return false; + }
+
+ return true;
+}
+
+CMLuaScript* CMLuaScript::GetScriptFromEnviroment(lua_State *L, int n)
+{
+ if (!GetScriptEnviroment(L, n)) + return NULL; lua_getfield(L, -1, SCRIPT);
- script = (CMLuaScript*)lua_touserdata(L, -1);
+ CMLuaScript *script = (CMLuaScript*)lua_touserdata(L, -1);
lua_pop(L, 3);
return script;
@@ -171,8 +168,8 @@ void CMLuaScript::Unload() lua_setfield(L, -2, moduleName);
lua_pop(L, 1);
- lua_pushnil(L);
- lua_setglobal(L, moduleName);
+ //lua_pushnil(L);
+ //lua_setglobal(L, moduleName);
KillModuleIcons(id);
KillModuleSounds(id);
diff --git a/plugins/MirLua/src/mlua_script.h b/plugins/MirLua/src/mlua_script.h index 742fc9ac75..68b382921e 100644 --- a/plugins/MirLua/src/mlua_script.h +++ b/plugins/MirLua/src/mlua_script.h @@ -24,8 +24,7 @@ public: CMLuaScript(lua_State *L, const TCHAR *path);
~CMLuaScript();
- //const int GetId() const;
-
+ static bool GetScriptEnviroment(lua_State *L, int n = 1);
static CMLuaScript* GetScriptFromEnviroment(lua_State *L, int n = 1);
static int GetScriptIdFromEnviroment(lua_State *L, int n = 1);
diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index 43d3a21990..f90db7243b 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -41,20 +41,6 @@ class CMLuaScript;
-struct luaM_const
-{
- char *name;
- 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"
@@ -81,6 +67,9 @@ extern HANDLE g_hScriptsFolder; #define MLUA_CORE "m_core"
LUAMOD_API int (luaopen_m_core)(lua_State *L);
+#define MLUA_CHAT "m_chat"
+LUAMOD_API int (luaopen_m_chat)(lua_State *L);
+
#define MLUA_CLIST "m_clist"
LUAMOD_API int (luaopen_m_clist)(lua_State *L);
@@ -118,16 +107,6 @@ LUAMOD_API int (luaopen_m_variables)(lua_State *L); /* utils */
-__forceinline void luaM_loadConsts(lua_State *L, luaM_const consts[])
-{
- for (size_t i = 0; consts[i].name != NULL; i++)
- {
- lua_pushstring(L, consts[i].name);
- lua_pushnumber(L, consts[i].value);
- lua_settable(L, -3);
- }
-}
-
extern HANDLE hNetlib;
void Log(const char *format, ...);
void Log(const wchar_t *format, ...);
@@ -148,9 +127,6 @@ bool luaM_toboolean(lua_State *L, int idx); WPARAM luaM_towparam(lua_State *L, int idx);
LPARAM luaM_tolparam(lua_State *L, int idx);
-CMLuaScript* GetScriptFromEnviroment(lua_State *L, int n = 1);
-int GetScriptIdFromEnviroment(lua_State *L, int n = 1);
-
void InitIcons();
HICON GetIcon(int iconId);
HANDLE GetIconHandle(int iconId);
|