From 0d024058a10f50365dffd6cebb0b8e10daccd78a Mon Sep 17 00:00:00 2001 From: IllidanS4 Date: Fri, 15 Feb 2019 23:47:43 +0100 Subject: [PATCH] array function --- plugins/src/lua_api.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/plugins/src/lua_api.cpp b/plugins/src/lua_api.cpp index 4bd7e8c..c7a15c8 100644 --- a/plugins/src/lua_api.cpp +++ b/plugins/src/lua_api.cpp @@ -411,6 +411,26 @@ static int exit(lua_State *L) return 0; } +static int array(lua_State *L) +{ + int top = lua_gettop(L); + if(top == 0) + { + lua_createtable(L, 0, 1); + }else{ + lua_createtable(L, top - 1, 2); + } + lua_insert(L, 1); + lua_pushinteger(L, top); + lua_setfield(L, 1, "n"); + while(top > 0) + { + lua_seti(L, 1, top - 1); + top--; + } + return 1; +} + static int open_package(lua_State *L) { luaopen_package(L); @@ -469,6 +489,9 @@ static int open_base(lua_State *L) lua_pushcfunction(L, exit); lua_setfield(L, -2, "exit"); + lua_pushcfunction(L, array); + lua_setfield(L, -2, "array"); + open_package(L); lua_pop(L, 1);