]> jfr.im git - irc/quakenet/newserv.git/blame - lua/lua.h
only define __USE_BSD if not defined
[irc/quakenet/newserv.git] / lua / lua.h
CommitLineData
2da56f0d
CP
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
f9b2dc0e 8#ifndef __USE_BSD
fe0f6b25 9#define __USE_BSD
f9b2dc0e 10#endif
fe0f6b25 11
2da56f0d
CP
12#include <lua.h>
13#include <lauxlib.h>
14#include <lualib.h>
15#include <string.h>
fe0f6b25
CP
16#include <sys/times.h>
17#include <sys/time.h>
18#include <sys/resource.h>
19#include <unistd.h>
2da56f0d
CP
20
21#include "../lib/sstring.h"
d0e17ef9 22#include "../core/nsmalloc.h"
2da56f0d 23
0225bed3 24#include "lualocal.h"
065c0091 25#include "luasocket.h"
0225bed3 26
d0e17ef9 27#define luamalloc(x) nsmalloc(POOL_LUA, x)
93917ccd 28#define luarealloc(x, y) nsrealloc(POOL_LUA, x, y)
d0e17ef9
CP
29#define luafree(x) nsfree(POOL_LUA, x)
30
fe0f6b25
CP
31/*** defines ************************************/
32
839f8d67 33#define LUA_BOTVERSION "1.90"
8566a7ed 34#define LUA_CHANFIXBOT "D"
ebe20bb8 35#define LUA_OPERCHAN "#twilightzone"
ba436ecf
CP
36
37#ifndef LUA_PUKECHAN
380a5b17 38#define LUA_PUKECHAN "#qnet.keepout"
ba436ecf 39#endif
ebe20bb8 40
fe0f6b25 41#define LUA_PROFILE
9887536a 42
9887536a
CP
43#define LUA_DEBUGSOCKET_ADDRESS "127.0.0.1"
44#define LUA_DEBUGSOCKET_PORT 7733
45
0225bed3
CP
46#ifdef LUA_USEJIT
47#include <luajit.h>
48#define LUA_AUXVERSION " + " LUAJIT_VERSION
49#else
b7252b44 50#define LUA_AUXVERSION ""
0225bed3
CP
51#endif
52
c3c955ee
CP
53#define LUA_SMALLVERSION "v" LUA_BOTVERSION " (" LUA_VERSION LUA_AUXVERSION ")"
54#define LUA_FULLVERSION "Lua engine " LUA_SMALLVERSION
0225bed3 55
fe0f6b25
CP
56/*** end defines ************************************/
57
2da56f0d
CP
58typedef struct lua_list {
59 lua_State *l;
60 sstring *name;
d0d1e2a3 61 unsigned long calls;
fe0f6b25 62 struct timeval ru_utime, ru_stime;
2da56f0d
CP
63 struct lua_list *next;
64 struct lua_list *prev;
0225bed3 65 lua_localnick *nicks;
065c0091 66 lua_socket *sockets;
2da56f0d
CP
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
d324e17b 73#define LUA_PATHLEN 150
2da56f0d
CP
74
75extern lua_list *lua_head;
6269435f 76extern sstring *cpath;
2da56f0d
CP
77
78lua_State *lua_loadscript(char *file);
79void lua_unloadscript(lua_list *l);
80lua_list *lua_scriptloaded(char *name);
d0d1e2a3 81lua_list *lua_listfromstate(lua_State *l);
55cee062 82int lua_listexists(lua_list *l);
0225bed3 83int lua_lineok(const char *data);
2da56f0d
CP
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)
0bb2fe5e
CP
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)
2da56f0d 95
fe0f6b25
CP
96extern struct rusage r_usages;
97extern 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
fe0f6b25
CP
112#endif
113
9887536a
CP
114#ifdef LUA_DEBUGSOCKET
115
bb4b25ee 116void lua_debugoutput(char *p, ...) __attribute__ ((format (printf, 1, 2)));
9887536a 117#define DEBUGOUT(p, ...) lua_debugoutput(p , ##__VA_ARGS__)
9887536a 118
2da56f0d
CP
119#endif
120
4f556cb0 121int lua_debugpcall(lua_State *l, char *message, int a, int b, int c);
ea15be33 122
9887536a 123#endif