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