diff options
| -rw-r--r-- | src/lua.h | 4 | ||||
| -rw-r--r-- | src/reg.c | 60 | ||||
| -rw-r--r-- | src/table.c | 12 | ||||
| -rw-r--r-- | src/table.h | 4 | ||||
| -rw-r--r-- | src/thread.c | 6 |
5 files changed, 38 insertions, 48 deletions
@@ -79,7 +79,7 @@ int writer(lua_State*, const void*, size_t, void*); #define lua_objlen(L,i) lua_rawlen(L,(i))
#define luaL_register(L, M, F) luaL_newlib(L, F);
-#elif LUA_VERSION_NUM = 501
+#elif LUA_VERSION_NUM == 501
#define luaL_tolstring lua_tolstring
#define lua_dump(A, B, C, D) lua_dump(A, B, C)
@@ -87,6 +87,8 @@ int writer(lua_State*, const void*, size_t, void*); #define lua_rawlen lua_objlen
#define lua_gc(A, B) lua_gc(A, B, 0)
+
+ #define lua_pushglobaltable(L) {lua_getglobal(L, "_G");}
#endif
@@ -7,22 +7,6 @@ #include "thread.h"
#include "test.h"
#include "config.h"
-#include <signal.h>
-#include <stdlib.h>
-
-void sigHandle(int s){
- //signal(s, SIG_IGN);
-
- //signal(s, sigHandle);
- exit(s);
-}
-
-static int lua_exit(lua_State* L){
-
- lib_thread_clean();
- //sigHandle(0);
- return 0;
-}
#define open_common(name)\
int luaopen_lullaby_##name (lua_State* L){\
@@ -48,34 +32,18 @@ open_common(test); int luaopen_lullaby(lua_State* L) {
- /*lua_newuserdata(L, 1);
- int ud = lua_gettop(L);
- lua_newtable(L);
- int meta = lua_gettop(L);
- luaI_tsetcf(L, meta, "__gc", lua_exit);
- lua_pushvalue(L, meta);
- lua_setmetatable(L, ud);*/
- //create <lib>.array functions
- lua_newtable(L);
- int top = lua_gettop(L);
- //lua_newtable(L);
-
- push(top, array);
- push(top, crypto);
- push(top, io);
- push(top, math);
- push(top, net);
- push(top, thread);
- push(top, test);
- luaI_tsets(L, top, "version", GIT_COMMIT)
-
- //lreg("array", array_function_list);
- //lreg("crypto", crypto_function_list);
- //lreg("io", io_function_list);
- //lreg("math", math_function_list);
- //lreg("config", config_function_list);
- //lreg("net", net_function_list);
- //lreg("thread", thread_function_list);
- lua_settop(L, top);
- return 1;
+ lua_newtable(L);
+ int top = lua_gettop(L);
+
+ push(top, array);
+ push(top, crypto);
+ push(top, io);
+ push(top, math);
+ push(top, net);
+ push(top, thread);
+ push(top, test);
+ luaI_tsets(L, top, "version", GIT_COMMIT)
+
+ lua_settop(L, top);
+ return 1;
}
diff --git a/src/table.c b/src/table.c index 6c3686a..593c31b 100644 --- a/src/table.c +++ b/src/table.c @@ -3,6 +3,18 @@ #include <string.h> #include <stdint.h> +int l_unpack(lua_State* L){ + int top = lua_gettop(L); + lua_pushnil(L); + + for(;lua_next(L, top);){ + lua_pushvalue(L, -2); + lua_remove(L, -3); + } + + return lua_gettop(L) - top; +} + uint64_t i_len(lua_State* L, int pos){ uint64_t i = 0; lua_pushnil(L); diff --git a/src/table.h b/src/table.h index a37dafc..e962e3c 100644 --- a/src/table.h +++ b/src/table.h @@ -19,6 +19,8 @@ int l_sindexof(lua_State*);//[double+int] (greatest -> least), item -> i int l_split(lua_State*); int l_to_char_array(lua_State*); +int l_unpack(lua_State*); + static const luaL_Reg array_function_list [] = { {"len",l_len}, {"reverse",l_reverse}, @@ -45,6 +47,8 @@ static const luaL_Reg array_function_list [] = { {"slowsort",l_slowsort}, {"bogosort",l_bogosort}, + {"unpack", l_unpack}, + {NULL,NULL} }; diff --git a/src/thread.c b/src/thread.c index c5ae933..f205165 100644 --- a/src/thread.c +++ b/src/thread.c @@ -8,6 +8,7 @@ #include "types/larray.h"
#include "hash/fnv.h"
+#include "table.h"
struct thread_info {
str* function;
@@ -338,6 +339,9 @@ void meta_proxy_gen(lua_State* L, struct thread_buffer *buffer, int meta_idx, in lua_pushlightuserdata(L, buffer);
lua_setglobal(L, "__this_obj");
+ lua_pushcfunction(L, l_unpack);
+ lua_setglobal(L, "__unpack");
+
lua_pushnil(L);
for(; lua_next(L, meta_idx) != 0;){
int k, v = lua_gettop(L);
@@ -346,7 +350,7 @@ void meta_proxy_gen(lua_State* L, struct thread_buffer *buffer, int meta_idx, in char* fn = calloc(128, sizeof * fn);
const char* key = lua_tostring(L, k);
sprintf(fn, "return function(_a,_b,_c)\
-return __proxy_call(__this_obj,'%s',table.unpack({_a,_b,_c}));end", key);
+return __proxy_call(__this_obj,'%s',__unpack({_a,_b,_c}));end", key);
luaL_dostring(L, fn);
free(fn);
|
