1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| lua_State * uh_lua_init(const char *handler) { lua_State *L = lua_open(); const char *err_str = NULL;
luaL_openlibs(L);
lua_newtable(L);
lua_pushcfunction(L, uh_lua_recv); lua_setfield(L, -2, "recv");
lua_pushcfunction(L, uh_lua_send); lua_setfield(L, -2, "send");
lua_pushcfunction(L, uh_lua_sendc); lua_setfield(L, -2, "sendc");
lua_pushcfunction(L, uh_lua_urldecode); lua_setfield(L, -2, "urldecode");
lua_setfield(L, LUA_GLOBALSINDEX, "uhttpd");
switch( luaL_loadfile(L, handler) ) { default: switch( lua_pcall(L, 0, 0, 0) ) { default: lua_getglobal(L, UH_LUA_CALLBACK);
if( ! lua_isfunction(L, -1) ){ fprintf(stderr, "Lua handler provides no " UH_LUA_CALLBACK "(), unable to continue\n"); exit(1); }
lua_pop(L, 1); break; } break; } return L; }
|