]> jfr.im git - irc/quakenet/newserv.git/blame - lua/lua.h
BUILD: add require-all build mode
[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"
72054e5b 26#include "luascheduler.h"
0225bed3 27
d0e17ef9 28#define luamalloc(x) nsmalloc(POOL_LUA, x)
93917ccd 29#define luarealloc(x, y) nsrealloc(POOL_LUA, x, y)
d0e17ef9
CP
30#define luafree(x) nsfree(POOL_LUA, x)
31
fe0f6b25
CP
32/*** defines ************************************/
33
e01edd32 34#define LUA_BOTVERSION "1.95"
3b752acf 35#define LUA_CHANFIXBOT "N2"
ebe20bb8 36#define LUA_OPERCHAN "#twilightzone"
ba436ecf
CP
37
38#ifndef LUA_PUKECHAN
380a5b17 39#define LUA_PUKECHAN "#qnet.keepout"
ba436ecf 40#endif
ebe20bb8 41
fe0f6b25 42#define LUA_PROFILE
9887536a 43
9887536a
CP
44#define LUA_DEBUGSOCKET_ADDRESS "127.0.0.1"
45#define LUA_DEBUGSOCKET_PORT 7733
46
0225bed3
CP
47#ifdef LUA_USEJIT
48#include <luajit.h>
49#define LUA_AUXVERSION " + " LUAJIT_VERSION
50#else
b7252b44 51#define LUA_AUXVERSION ""
0225bed3
CP
52#endif
53
c3c955ee
CP
54#define LUA_SMALLVERSION "v" LUA_BOTVERSION " (" LUA_VERSION LUA_AUXVERSION ")"
55#define LUA_FULLVERSION "Lua engine " LUA_SMALLVERSION
0225bed3 56
fe0f6b25
CP
57/*** end defines ************************************/
58
2da56f0d
CP
59typedef struct lua_list {
60 lua_State *l;
61 sstring *name;
d0d1e2a3 62 unsigned long calls;
fe0f6b25 63 struct timeval ru_utime, ru_stime;
2da56f0d
CP
64 struct lua_list *next;
65 struct lua_list *prev;
7697f3b1
CP
66 struct {
67 int attempted_load;
68 void *db;
69 } db;
0225bed3 70 lua_localnick *nicks;
065c0091 71 lua_socket *sockets;
72054e5b 72 lua_scheduler *schedulers;
2da56f0d
CP
73} lua_list;
74
75#define LUA_STARTLOOP(l) { lua_list *ll; for(ll=lua_head;ll;ll=ll->next) { l = ll->l
76
77#define LUA_ENDLOOP() } }
78
d324e17b 79#define LUA_PATHLEN 150
2da56f0d
CP
80
81extern lua_list *lua_head;
6269435f 82extern sstring *cpath;
2da56f0d
CP
83
84lua_State *lua_loadscript(char *file);
85void lua_unloadscript(lua_list *l);
86lua_list *lua_scriptloaded(char *name);
d0d1e2a3 87lua_list *lua_listfromstate(lua_State *l);
55cee062 88int lua_listexists(lua_list *l);
0225bed3 89int lua_lineok(const char *data);
2da56f0d
CP
90
91#define lua_toint(l, n) (int)lua_tonumber(l, n)
92#define lua_isint(l, n) lua_isnumber(l, n)
93#define lua_pushint(l, n) lua_pushnumber(l, n)
94
95#define lua_tolong(l, n) (long)lua_tonumber(l, n)
96#define lua_islong(l, n) lua_isnumber(l, n)
97#define lua_pushlong(l, n) lua_pushnumber(l, n)
0bb2fe5e
CP
98#define lua_pushnumeric(l, n) lua_pushlong(l, n)
99#define lua_tonumeric(l, n) lua_tolong(l, n)
100#define lua_isnumeric(l, n) lua_islong(l, n)
2da56f0d 101
fe0f6b25
CP
102extern struct rusage r_usages;
103extern struct rusage r_usagee;
104
105#define USEC_DIFFERENTIAL 1000000
106
107#ifdef LUA_PROFILE
108
109#define ACCOUNTING_START(l) { l->calls++; getrusage(RUSAGE_SELF, &r_usages);
110
111#define twrap(A2, B2, C2, D2) A2(&(B2), &(C2), &(D2))
112
113#define _SET_2TIMEDIFF(L4, S2, E2, I2) twrap(timersub, E2.I2, S2.I2, E2.I2); twrap(timeradd, L4->I2, E2.I2, L4->I2);
114#define SET_TIMEDIFF(L3, S2, E2) _SET_2TIMEDIFF(L3, S2, E2, ru_utime); _SET_2TIMEDIFF(L3, S2, E2, ru_stime);
115
116#define ACCOUNTING_STOP(l) getrusage(RUSAGE_SELF, &r_usagee); SET_TIMEDIFF(l, r_usages, r_usagee); }
117
fe0f6b25
CP
118#endif
119
9887536a
CP
120#ifdef LUA_DEBUGSOCKET
121
bb4b25ee 122void lua_debugoutput(char *p, ...) __attribute__ ((format (printf, 1, 2)));
9887536a 123#define DEBUGOUT(p, ...) lua_debugoutput(p , ##__VA_ARGS__)
9887536a 124
2da56f0d
CP
125#endif
126
4f556cb0 127int lua_debugpcall(lua_State *l, char *message, int a, int b, int c);
ea15be33 128
9887536a 129#endif