diff --git a/lualib-src/lua-skynet.c b/lualib-src/lua-skynet.c index 502894b2..cca9d768 100644 --- a/lualib-src/lua-skynet.c +++ b/lualib-src/lua-skynet.c @@ -1,6 +1,5 @@ #include "skynet.h" #include "lua-seri.h" -#include "service_lua.h" #define KNRM "\x1B[0m" #define KRED "\x1B[31m" @@ -11,6 +10,12 @@ #include #include +struct snlua { + lua_State * L; + struct skynet_context * ctx; + const char * preload; +}; + static int _cb(struct skynet_context * context, void * ud, int type, int session, uint32_t source, const void * msg, size_t sz) { lua_State *L = ud; @@ -290,15 +295,14 @@ luaopen_skynet_c(lua_State *L) { { NULL, NULL }, }; - lua_getfield(L, LUA_REGISTRYINDEX, "skynet_lua"); - struct snlua *lua = lua_touserdata(L,-1); - if (lua == NULL || lua->ctx == NULL) { + luaL_newlibtable(L, l); + + lua_getfield(L, LUA_REGISTRYINDEX, "skynet_context"); + struct skynet_context *ctx = lua_touserdata(L,-1); + if (ctx == NULL) { return luaL_error(L, "Init skynet context first"); } - assert(lua->L == L); - luaL_newlibtable(L, l); - lua_pushlightuserdata(L, lua->ctx); luaL_setfuncs(L,l,1); return 1; diff --git a/lualib-src/lua-socket.c b/lualib-src/lua-socket.c index c3ba9f3b..3f22956c 100644 --- a/lualib-src/lua-socket.c +++ b/lualib-src/lua-socket.c @@ -10,7 +10,6 @@ #include #include "skynet_socket.h" -#include "service_lua.h" #define BACKLOG 32 // 2 ** 12 == 4096 @@ -485,15 +484,12 @@ luaopen_socketdriver(lua_State *L) { { "start", lstart }, { NULL, NULL }, }; - lua_getfield(L, LUA_REGISTRYINDEX, "skynet_lua"); - struct snlua *lua = lua_touserdata(L,-1); - if (lua == NULL || lua->ctx == NULL) { + lua_getfield(L, LUA_REGISTRYINDEX, "skynet_context"); + struct skynet_context *ctx = lua_touserdata(L,-1); + if (ctx == NULL) { return luaL_error(L, "Init skynet context first"); } - // assert(lua->L == L); - lua_pop(L,1); - lua_pushlightuserdata(L, lua->ctx); luaL_setfuncs(L,l2,1); return 1; diff --git a/service-src/service_lua.h b/service-src/service_lua.h deleted file mode 100644 index d20420fd..00000000 --- a/service-src/service_lua.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef SKYNET_SERVICE_LUA_H -#define SKYNET_SERVICE_LUA_H - -struct snlua { - lua_State * L; - struct skynet_context * ctx; - const char * preload; -}; - -#endif diff --git a/service-src/service_snlua.c b/service-src/service_snlua.c index 7dc314f3..07fb830b 100644 --- a/service-src/service_snlua.c +++ b/service-src/service_snlua.c @@ -4,13 +4,18 @@ #include #include #include -#include "service_lua.h" #include #include #include #include +struct snlua { + lua_State * L; + struct skynet_context * ctx; + const char * preload; +}; + // LUA_CACHELIB may defined in patched lua for shared proto #ifdef LUA_CACHELIB @@ -189,8 +194,8 @@ _init(struct snlua *l, struct skynet_context *ctx, const char * args) { l->ctx = ctx; lua_gc(L, LUA_GCSTOP, 0); luaL_openlibs(L); - lua_pushlightuserdata(L, l); - lua_setfield(L, LUA_REGISTRYINDEX, "skynet_lua"); + lua_pushlightuserdata(L, ctx); + lua_setfield(L, LUA_REGISTRYINDEX, "skynet_context"); luaL_requiref(L, "skynet.codecache", codecache , 0); lua_pop(L,1);