]> jfr.im git - irc/quakenet/newserv.git/blob - lua/lua.h
e9736812a72293dcc5638642ba4c0cb07334d3eb
[irc/quakenet/newserv.git] / lua / lua.h
1 /* Copyright (C) Chris Porter 2005 */
2 /* ALL RIGHTS RESERVED. */
3 /* Don't put this into the SVN repo. */
4
5 #ifndef _LUA_H
6 #define _LUA_H
7
8 #define __USE_BSD
9
10 #include <lua.h>
11 #include <lauxlib.h>
12 #include <lualib.h>
13 #include <string.h>
14 #include <sys/times.h>
15 #include <sys/time.h>
16 #include <sys/resource.h>
17 #include <unistd.h>
18
19 #include "../lib/sstring.h"
20 #include "../core/nsmalloc.h"
21
22 #include "lualocal.h"
23 #include "luasocket.h"
24
25 #define luamalloc(x) nsmalloc(POOL_LUA, x)
26 #define luarealloc(x, y) nsrealloc(POOL_LUA, x, y)
27 #define luafree(x) nsfree(POOL_LUA, x)
28
29 /*** defines ************************************/
30
31 #define LUA_BOTVERSION "1.89"
32 #define LUA_CHANFIXBOT "D"
33 #define LUA_OPERCHAN "#twilightzone"
34
35 #ifndef LUA_PUKECHAN
36 #define LUA_PUKECHAN "#qnet.keepout"
37 #endif
38
39 #define LUA_PROFILE
40
41 #define LUA_DEBUGSOCKET_ADDRESS "127.0.0.1"
42 #define LUA_DEBUGSOCKET_PORT 7733
43
44 #ifdef LUA_USEJIT
45 #include <luajit.h>
46 #define LUA_AUXVERSION " + " LUAJIT_VERSION
47 #else
48 #define LUA_AUXVERSION ""
49 #endif
50
51 #define LUA_SMALLVERSION "v" LUA_BOTVERSION " (" LUA_VERSION LUA_AUXVERSION ")"
52 #define LUA_FULLVERSION "Lua engine " LUA_SMALLVERSION
53
54 /*** end defines ************************************/
55
56 typedef struct lua_list {
57 lua_State *l;
58 sstring *name;
59 unsigned long calls;
60 struct timeval ru_utime, ru_stime;
61 struct lua_list *next;
62 struct lua_list *prev;
63 lua_localnick *nicks;
64 lua_socket *sockets;
65 } lua_list;
66
67 #define LUA_STARTLOOP(l) { lua_list *ll; for(ll=lua_head;ll;ll=ll->next) { l = ll->l
68
69 #define LUA_ENDLOOP() } }
70
71 #define LUA_PATHLEN 150
72
73 extern lua_list *lua_head;
74 extern sstring *cpath;
75
76 lua_State *lua_loadscript(char *file);
77 void lua_unloadscript(lua_list *l);
78 lua_list *lua_scriptloaded(char *name);
79 lua_list *lua_listfromstate(lua_State *l);
80 int lua_listexists(lua_list *l);
81 int lua_lineok(const char *data);
82
83 #define lua_toint(l, n) (int)lua_tonumber(l, n)
84 #define lua_isint(l, n) lua_isnumber(l, n)
85 #define lua_pushint(l, n) lua_pushnumber(l, n)
86
87 #define lua_tolong(l, n) (long)lua_tonumber(l, n)
88 #define lua_islong(l, n) lua_isnumber(l, n)
89 #define lua_pushlong(l, n) lua_pushnumber(l, n)
90 #define lua_pushnumeric(l, n) lua_pushlong(l, n)
91 #define lua_tonumeric(l, n) lua_tolong(l, n)
92 #define lua_isnumeric(l, n) lua_islong(l, n)
93
94 extern struct rusage r_usages;
95 extern struct rusage r_usagee;
96
97 #define USEC_DIFFERENTIAL 1000000
98
99 #ifdef LUA_PROFILE
100
101 #define ACCOUNTING_START(l) { l->calls++; getrusage(RUSAGE_SELF, &r_usages);
102
103 #define twrap(A2, B2, C2, D2) A2(&(B2), &(C2), &(D2))
104
105 #define _SET_2TIMEDIFF(L4, S2, E2, I2) twrap(timersub, E2.I2, S2.I2, E2.I2); twrap(timeradd, L4->I2, E2.I2, L4->I2);
106 #define SET_TIMEDIFF(L3, S2, E2) _SET_2TIMEDIFF(L3, S2, E2, ru_utime); _SET_2TIMEDIFF(L3, S2, E2, ru_stime);
107
108 #define ACCOUNTING_STOP(l) getrusage(RUSAGE_SELF, &r_usagee); SET_TIMEDIFF(l, r_usages, r_usagee); }
109
110 #endif
111
112 #ifdef LUA_DEBUGSOCKET
113
114 void lua_debugoutput(char *p, ...) __attribute__ ((format (printf, 1, 2)));
115 #define DEBUGOUT(p, ...) lua_debugoutput(p , ##__VA_ARGS__)
116
117 #endif
118
119 int lua_debugpcall(lua_State *l, char *message, int a, int b, int c);
120
121 #endif