Skip to content

Commit

Permalink
array function
Browse files Browse the repository at this point in the history
  • Loading branch information
IS4Code committed Feb 15, 2019
1 parent 9ca906c commit 0d02405
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions plugins/src/lua_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 0d02405

Please sign in to comment.