/* ALL RIGHTS RESERVED. */
/* Don't put this into the SVN repo. */
+#define _POSIX_C_SOURCE 200112L
+#include <stdlib.h>
+
#include "../core/config.h"
#include "../core/error.h"
#include "../core/hooks.h"
#include "../lib/irc_string.h"
#include "../core/schedule.h"
#include "../lib/version.h"
-
+#include "../lib/strlfunc.h"
#include "lua.h"
-MODULE_VERSION(LUA_FULLVERSION);
+MODULE_VERSION(LUA_SMALLVERSION);
#ifdef LUA_DEBUGSOCKET
void lua_onunload(lua_State *l);
void lua_onload(lua_State *l);
-void lua_setpath(lua_State *l);
+void lua_setpath(void);
void lua_setupdebugsocket(void);
void lua_freedebugsocket(void);
return;
}
+ lua_setpath();
+
loaded = 1;
startsched = scheduleoneshot(time(NULL) + 1, &lua_startup, NULL);
int top;
lua_State *l;
lua_list *n;
+ char buf[1024];
if(!cpath || !suffix)
return NULL;
- delchars(file, "./\\;");
+ strlcpy(buf, file, sizeof(buf));
+
+ delchars(buf, "./\\;");
- if(lua_scriptloaded(file))
+ if(lua_scriptloaded(buf))
return NULL;
l = lua_newstate(lua_nsmalloc, NULL);
n = (lua_list *)luamalloc(sizeof(lua_list));;
if(!n) {
- Error("lua", ERR_ERROR, "Error allocing list for %s.", file);
+ Error("lua", ERR_ERROR, "Error allocing list for %s.", buf);
return NULL;
}
- n->name = getsstring(file, LUA_PATHLEN);
+ n->name = getsstring(buf, LUA_PATHLEN);
if(!n->name) {
- Error("lua", ERR_ERROR, "Error allocing name item for %s.", file);
+ Error("lua", ERR_ERROR, "Error allocing name item for %s.", buf);
luafree(n);
return NULL;
}
lua_registersocketcommands(l);
lua_registercryptocommands(l);
- lua_setpath(l);
-
#ifdef LUA_USEJIT
lua_require(l, "lib/jit");
#endif
luafree(l);
}
-void lua_setpath(lua_State *l) {
- char fullpath[LUA_PATHLEN], *prev = NULL;
-
- int top = lua_gettop(l);
-
- lua_getglobal(l, "package");
- if(!lua_istable(l, 1)) {
- Error("lua", ERR_ERROR, "Unable to set package.path (package is not a table).");
- return;
- }
-
- lua_pushstring(l, "path");
- lua_gettable(l, -2);
-
- if(lua_isstring(l, -1))
- prev = (char *)lua_tostring(l, -1);
-
- if(prev) {
- snprintf(fullpath, sizeof(fullpath), "%s;%s/?%s", prev, cpath->content, suffix->content);
- } else {
- snprintf(fullpath, sizeof(fullpath), "%s/?%s", cpath->content, suffix->content);
- }
-
- /* pop broke! */
-
- lua_getglobal(l, "package");
- if(!lua_istable(l, 1)) {
- Error("lua", ERR_ERROR, "Unable to set package.path (package is not a table).");
- return;
- }
-
- lua_pushstring(l, "path");
-
- lua_pushstring(l, fullpath);
- lua_settable(l, -3);
+void lua_setpath(void) {
+ char fullpath[LUA_PATHLEN];
- lua_settop(l, top);
+ snprintf(fullpath, sizeof(fullpath), "%s/?%s", cpath->content, suffix->content);
+ setenv("LUA_PATH", fullpath, 1);
}
lua_list *lua_scriptloaded(char *name) {
return 1;
}
-INLINE int lua_debugpcall(lua_State *l, char *message, int a, int b, int c) {
+int lua_debugpcall(lua_State *l, char *message, int a, int b, int c) {
lua_list *l2 = lua_listfromstate(l);
int ret;