diff options
Diffstat (limited to 'accel-pppd/ctrl/ipoe/lua.c')
-rw-r--r-- | accel-pppd/ctrl/ipoe/lua.c | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/accel-pppd/ctrl/ipoe/lua.c b/accel-pppd/ctrl/ipoe/lua.c index 77beca6e..0b24635f 100644 --- a/accel-pppd/ctrl/ipoe/lua.c +++ b/accel-pppd/ctrl/ipoe/lua.c @@ -185,6 +185,12 @@ static void init_lua() if (lua_pcall(L, 0, 0, 0)) goto out_err; + lua_pushlightuserdata(L, L); + luaL_getmetatable(L, IPOE_PACKET4); + lua_setmetatable(L, -2); + + lua_settop(L, 0); + file_error = 0; pthread_setspecific(__key, L); @@ -198,6 +204,29 @@ out_err: L = NULL; } +/*static void stackDump (lua_State *L) { + int i=lua_gettop(L); + printf(" ---------------- Stack Dump ----------------" ); + while( i ) { + int t = lua_type(L, i); + switch (t) { + case LUA_TSTRING: + printf("%d:`%s'\n", i, lua_tostring(L, i)); + break; + case LUA_TBOOLEAN: + printf("%d: %s\n",i,lua_toboolean(L, i) ? "true" : "false"); + break; + case LUA_TNUMBER: + printf("%d: %g\n", i, lua_tonumber(L, i)); + break; + default: printf("%d: %s\n", i, lua_typename(L, t)); break; + } + i--; + } + printf("--------------- Stack Dump Finished ---------------" ); + }*/ + + int ipoe_lua_set_username(struct ipoe_session *ses, const char *func) { if (file_error && serial == __serial) @@ -211,27 +240,31 @@ int ipoe_lua_set_username(struct ipoe_session *ses, const char *func) if (!L) return -1; - + lua_getglobal(L, func); lua_pushlightuserdata(L, ses); - luaL_getmetatable(L, IPOE_PACKET4); - lua_setmetatable(L, -2); if (lua_pcall(L, 1, 1, 0)) { log_ppp_error("ipoe: lua: %s\n", lua_tostring(L, -1)); - return -1; + goto out_err; } if (!lua_isstring(L, -1)) { log_ppp_error("ipoe: lua: function '%s' must return a string\n", func); - return -1; + goto out_err; } ses->ses.username = _strdup(lua_tostring(L, -1)); - lua_pop(L, 1); + lua_settop(L, 0); return 0; + +out_err: + file_error = 1; + lua_close(L); + L = NULL; + return -1; } static void load_config() |