#include "lua.h"
-MODULE_VERSION(LUA_FULLVERSION " / $Id: lua.c 699 2006-06-07 14:17:26Z newserv $")
+MODULE_VERSION(LUA_SMALLVERSION);
#ifdef LUA_DEBUGSOCKET
void lua_startup(void *arg);
void lua_loadscripts(void);
void lua_registercommands(lua_State *l);
+void lua_registerdbcommands(lua_State *l);
void lua_initnickpusher(void);
void lua_initchanpusher(void);
void lua_loadlibs(lua_State *l);
void lua_deregisternicks(lua_list *l);
void lua_registerlocalcommands(lua_State *ps);
void lua_registerdebug(lua_State *ps);
+void lua_socket_closeall(lua_list *l);
+void lua_registersocketcommands(lua_State *ps);
+void lua_registercryptocommands(lua_State *ps);
#ifdef LUA_DEBUGSOCKET
freesstring(dummy.name);
lua_freedebugsocket();
+ nscheckfreeall(POOL_LUA);
}
void lua_loadscripts(void) {
}
}
+/* taken from the lua manual, modified to use nsmalloc */
+static void *lua_nsmalloc(void *ud, void *ptr, size_t osize, size_t nsize) {
+ if(nsize == 0) {
+ if(ptr != NULL)
+ luafree(ptr);
+ return NULL;
+ }
+
+ return luarealloc(ptr, nsize);
+}
+
lua_State *lua_loadscript(char *file) {
char fullpath[LUA_PATHLEN];
int top;
if(lua_scriptloaded(file))
return NULL;
- l = lua_open();
+ l = lua_newstate(lua_nsmalloc, NULL);
if(!l)
return NULL;
- n = (lua_list *)malloc(sizeof(lua_list));;
+ n = (lua_list *)luamalloc(sizeof(lua_list));;
if(!n) {
Error("lua", ERR_ERROR, "Error allocing list for %s.", file);
return NULL;
n->name = getsstring(file, LUA_PATHLEN);
if(!n->name) {
Error("lua", ERR_ERROR, "Error allocing name item for %s.", file);
- free(n);
+ luafree(n);
return NULL;
}
n->calls = 0;
lua_registerdebug(l);
lua_registercommands(l);
lua_registerlocalcommands(l);
+ lua_registerdbcommands(l);
+ lua_registersocketcommands(l);
+ lua_registercryptocommands(l);
lua_setpath(l);
Error("lua", ERR_ERROR, "Error loading %s.", file);
lua_close(l);
freesstring(n->name);
- free(n);
- return NULL;
- }
-
- top = lua_gettop(l);
-
- if(lua_pcall(l, 0, 0, 0)) {
- Error("lua", ERR_ERROR, "Error pcalling: %s.", file);
- lua_close(l);
- freesstring(n->name);
- free(n);
+ luafree(n);
return NULL;
}
- lua_settop(l, top);
-
- Error("lua", ERR_INFO, "Loaded %s.", file);
n->l = l;
n->next = NULL;
n->prev = lua_tail;
n->nicks = NULL;
+ n->sockets = NULL;
if(!lua_head) {
lua_head = n;
lua_tail = n;
+ top = lua_gettop(l);
+
+ if(lua_pcall(l, 0, 0, 0)) {
+ Error("lua", ERR_ERROR, "Error pcalling: %s.", file);
+ lua_close(l);
+ freesstring(n->name);
+
+ if(lua_head == n)
+ lua_head = NULL;
+
+ lua_tail = n->prev;
+ if(lua_tail)
+ lua_tail->next = NULL;
+
+ luafree(n);
+ return NULL;
+ }
+
+ lua_settop(l, top);
+
+ Error("lua", ERR_INFO, "Loaded %s.", file);
lua_onload(l);
return l;
void lua_unloadscript(lua_list *l) {
lua_onunload(l->l);
lua_deregisternicks(l);
+ lua_socket_closeall(l);
lua_close(l->l);
freesstring(l->name);
}
}
- free(l);
+ luafree(l);
}
void lua_setpath(lua_State *l) {
return &dummy;
}
+int lua_listexists(lua_list *l) {
+ lua_list *i;
+
+ for(i=lua_head;i;i=i->next)
+ if(i == l)
+ return 1;
+
+ return 0;
+}
+
int lua_lineok(const char *data) {
if(strchr(data, '\r') || strchr(data, '\n'))
return 0;