summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/mlua_utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/MirLua/src/mlua_utils.cpp')
-rw-r--r--plugins/MirLua/src/mlua_utils.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp
index e4ea3efd11..26bcf22657 100644
--- a/plugins/MirLua/src/mlua_utils.cpp
+++ b/plugins/MirLua/src/mlua_utils.cpp
@@ -249,7 +249,7 @@ bool luaM_toboolean(lua_State *L, int idx)
/***********************************************/
-static int blob_create(lua_State *L)
+static int blob_new(lua_State *L)
{
BYTE *data = (BYTE*)lua_touserdata(L, 1);
size_t size = luaL_checkinteger(L, 2);
@@ -263,6 +263,17 @@ static int blob_create(lua_State *L)
return 1;
}
+static int blob_call(lua_State *L)
+{
+ int nargs = lua_gettop(L);
+ lua_pushcfunction(L, blob_new);
+ for (int i = 2; i <= nargs; i++)
+ lua_pushvalue(L, i);
+ luaM_pcall(L, nargs - 1, 1);
+
+ return 1;
+}
+
static int blob__index(lua_State *L)
{
BLOB *blob = (BLOB*)luaL_checkudata(L, 1, MT_BLOB);
@@ -303,6 +314,7 @@ static int blob__gc(lua_State *L)
static const struct luaL_Reg blobApi[] =
{
+ { "__call", blob_call },
{ "__index", blob__index },
{ "__newindex", blob__newindex },
{ "__len", blob__len },
@@ -313,10 +325,17 @@ static const struct luaL_Reg blobApi[] =
int luaopen_m_utils(lua_State *L)
{
- lua_register(L, MT_BLOB, blob_create);
luaL_newmetatable(L, MT_BLOB);
luaL_setfuncs(L, blobApi, 0);
lua_pop(L, 1);
+ lua_createtable(L, 0, 1);
+ lua_pushcfunction(L, blob_new);
+ lua_setfield(L, -2, "new");
+ lua_pushvalue(L, -1);
+ lua_setglobal(L, MT_BLOB);
+ luaL_setmetatable(L, MT_BLOB);
+ lua_pop(L, 1);
+
return 0;
} \ No newline at end of file