]> jfr.im git - irc/quakenet/newserv.git/blob - lua/lua.h
Add multiple mode changes at once.
[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
21 #include "lualocal.h"
22
23 /*** defines ************************************/
24
25 #define LUA_BOTVERSION "1.60"
26 #define LUA_CHANFIXBOT "Z"
27 #define LUA_OPERCHAN "#twilightzone"
28
29 #ifndef LUA_PUKECHAN
30 #define LUA_PUKECHAN "#qnet.keepout"
31 #endif
32
33 #define LUA_PROFILE
34
35 #ifndef LUA_NOJIT
36 #define LUA_USEJIT
37 #endif
38
39 #define LUA_DEBUGSOCKET_ADDRESS "127.0.0.1"
40 #define LUA_DEBUGSOCKET_PORT 7733
41
42 #ifdef LUA_USEJIT
43 #include <luajit.h>
44 #define LUA_AUXVERSION " + " LUAJIT_VERSION
45 #else
46 #define LUA_AUXVERSION ""
47 #endif
48
49 #define LUA_FULLVERSION "Lua engine v" LUA_BOTVERSION " (" LUA_VERSION LUA_AUXVERSION ")"
50
51 /*** end defines ************************************/
52
53 typedef struct lua_list {
54 lua_State *l;
55 sstring *name;
56 unsigned long calls;
57 struct timeval ru_utime, ru_stime;
58 struct lua_list *next;
59 struct lua_list *prev;
60 lua_localnick *nicks;
61 } lua_list;
62
63 #define LUA_STARTLOOP(l) { lua_list *ll; for(ll=lua_head;ll;ll=ll->next) { l = ll->l
64
65 #define LUA_ENDLOOP() } }
66
67 #define LUA_PATHLEN 1024
68
69 extern lua_list *lua_head;
70 extern sstring *cpath;
71
72 lua_State *lua_loadscript(char *file);
73 void lua_unloadscript(lua_list *l);
74 lua_list *lua_scriptloaded(char *name);
75 lua_list *lua_listfromstate(lua_State *l);
76 int lua_lineok(const char *data);
77
78 #define lua_toint(l, n) (int)lua_tonumber(l, n)
79 #define lua_isint(l, n) lua_isnumber(l, n)
80 #define lua_pushint(l, n) lua_pushnumber(l, n)
81
82 #define lua_tolong(l, n) (long)lua_tonumber(l, n)
83 #define lua_islong(l, n) lua_isnumber(l, n)
84 #define lua_pushlong(l, n) lua_pushnumber(l, n)
85
86 extern struct rusage r_usages;
87 extern struct rusage r_usagee;
88
89 #define USEC_DIFFERENTIAL 1000000
90
91 #ifdef LUA_PROFILE
92
93 #define ACCOUNTING_START(l) { l->calls++; getrusage(RUSAGE_SELF, &r_usages);
94
95 #define twrap(A2, B2, C2, D2) A2(&(B2), &(C2), &(D2))
96
97 #define _SET_2TIMEDIFF(L4, S2, E2, I2) twrap(timersub, E2.I2, S2.I2, E2.I2); twrap(timeradd, L4->I2, E2.I2, L4->I2);
98 #define SET_TIMEDIFF(L3, S2, E2) _SET_2TIMEDIFF(L3, S2, E2, ru_utime); _SET_2TIMEDIFF(L3, S2, E2, ru_stime);
99
100 #define ACCOUNTING_STOP(l) getrusage(RUSAGE_SELF, &r_usagee); SET_TIMEDIFF(l, r_usages, r_usagee); }
101
102 #else
103
104 #define ACCOUNTING_START(l) ;
105 #define ACCOUNTING_STOP(l) ;
106
107 #endif
108
109 #ifdef LUA_DEBUGSOCKET
110
111 void lua_debugoutput(char *p, ...);
112 #define DEBUGOUT(p, ...) lua_debugoutput(p , ##__VA_ARGS__)
113 #define lua_debugpcall(l, message, ...) { lua_list *l2 = lua_listfromstate(l); DEBUGOUT("%s: %s\n", l2->name->content, message); ACCOUNTING_START(l2); lua_pcall(l , ##__VA_ARGS__); ACCOUNTING_STOP(l2); }
114
115 #else
116
117 #define DEBUGOUT(p, ...)
118
119 #ifdef LUA_PROFILE
120 #define lua_debugpcall(l, message, ...) { lua_list *l2 = lua_listfromstate(l); ACCOUNTING_START(l2); lua_pcall(l , ##__VA_ARGS__); ACCOUNTING_STOP(l2); }
121 #else
122 #define lua_debugpcall(l, message, ...) lua_pcall(l , ##__VA_ARGS__); ACCOUNTING_STOP(l2);
123 #endif
124
125 #endif
126
127 #ifndef INLINE
128
129 #ifdef __GNUC__
130 #define INLINE __attribute((always_inline)) inline
131 #endif
132
133 #ifdef _MSC_VER
134 #define INLINE __forceinline
135 #endif
136
137 #ifndef INLINE
138 #define INLINE inline
139 #endif
140
141 #endif /* INLINE */
142
143 #endif