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