summaryrefslogtreecommitdiff
path: root/src/lua/tolua.h
blob: ab86976cc2eacbb091421c0827c5942829976dbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* tolua - Support code for Lua bindings.
** Written by Waldemar Celes (celes@tecgraf.puc-rio.br)
** TeCGraf/PUC-Rio
** http://www.tecgraf.puc-rio.br/~celes/tolua
** Jul 1998
** $Id: tolua.h,v 1.2 2001/11/26 23:00:27 darkgod Exp $
*/

/* This code is free software; you can redistribute it and/or modify it.
** The software provided hereunder is on an "as is" basis, and
** the author has no obligation to provide maintenance, support, updates,
** enhancements, or modifications.
*/


#ifndef tolua_h
#define tolua_h

#define TOLUA_VERSION       "tolua 4.0a - angband"


#include <stdlib.h>		/* NULL, malloc, free */

#ifdef __cplusplus
extern "C" {
#endif

#include "lua.h"

/* Evil hack for C++ bool_ vs. C bool. */
#ifndef __cplusplus
typedef unsigned char bool;
#endif

/*************************************** Exported functions */

int   tolua_open (lua_State* L);
void  tolua_using (lua_State* L, int module);
void  tolua_class (lua_State* L, int derived, int base);
void  tolua_instance (lua_State* L, int instance, int classobj);
void  tolua_foreach (lua_State* L, int lo, int f);
int   tolua_tag (lua_State* L, char* type);
const char* tolua_type (lua_State* L, int lo);
int   tolua_base (lua_State* L, int lo);
int   tolua_cast (lua_State* L, int lo, char* type);
void  tolua_takeownership (lua_State* L, int lo);



/*************************************** Support functions for binding code */

#define LUA_VALUE int
#define LUA_NIL 0 /* TODO */
/*#define TOLUA_NIL	(lua_pushnil(),lua_pop())*/

/* Register functions */
void tolua_globalvar (lua_State* L, char* name, lua_CFunction get, lua_CFunction set);
void tolua_globalarray (lua_State* L, char* name, lua_CFunction get, lua_CFunction set);
void tolua_module (lua_State* L, char* name);
void tolua_cclass (lua_State* L, char* name, char* base);
void tolua_function (lua_State* L, char* parent, char* name, lua_CFunction func);
void tolua_constant (lua_State* L, char* parent, char* name, long value);
void tolua_tablevar
(lua_State* L, char* table, char* name, lua_CFunction get, lua_CFunction set);
void tolua_tablearray
(lua_State* L, char* table, char* name, lua_CFunction get, lua_CFunction set);


/* Get and push functions */
long tolua_getnumber (lua_State* L, int narg, long def);
const char* tolua_getstring (lua_State* L, int narg, const char* def);
void* tolua_getuserdata (lua_State* L, int narg, void* def);
void* tolua_getusertype (lua_State* L, int narg, void* def);
int   tolua_getvalue (lua_State* L, int narg, int def);
int   tolua_getbool (lua_State* L, int narg, int def);
long tolua_getfieldnumber (lua_State* L, int lo, int index, long def);
const char* tolua_getfieldstring (lua_State* L, int lo, int index, const char* def);
void* tolua_getfielduserdata (lua_State* L, int lo, int index, void* def);
void* tolua_getfieldusertype (lua_State* L, int lo, int index, void* def);
int tolua_getfieldvalue (lua_State* L, int lo, int index, int def);
int tolua_getfieldbool (lua_State* L, int lo, int index, int def);

void tolua_pushnumber (lua_State* L, long value);
void tolua_pushstring (lua_State* L, const char* value);
void tolua_pushuserdata (lua_State* L, void* value);
void tolua_pushusertype (lua_State* L, void* value, int tag);
void tolua_pushvalue (lua_State* L, int lo);
void tolua_pushbool (lua_State* L, int value);
void tolua_pushfieldnumber (lua_State* L, int lo, int index, long v);
void tolua_pushfieldstring (lua_State* L, int lo, int index, char* v);
void tolua_pushfielduserdata (lua_State* L, int lo, int index, void* v);
void tolua_pushfieldusertype (lua_State* L, int lo, int index, void* v, int tag);
void tolua_pushfieldvalue (lua_State* L, int lo, int index, int v);
void tolua_pushfieldbool (lua_State* L, int lo, int index, int v);


/* Type & tag manipulation */
void tolua_usertype (lua_State* L, char* type);
#if 0
void tolua_settag (lua_State* L, char* type, int* tag);
#endif
int  tolua_istype (lua_State* L, int narg, int tag, int dim);
int  tolua_arrayistype (lua_State* L, int narg, int tag, int dim, int def);

int  tolua_isnoobj (lua_State* L, int narg);

/* Tag method manipulation */
void* tolua_doclone (lua_State* L, void* value, int tag);
void* tolua_copy (lua_State* L, void* value, unsigned int size);

/* Error handling */
void tolua_error (lua_State* L, char* msg);

/* Exported variables */
extern int tolua_tag_nil;
extern int tolua_tag_number;
extern int tolua_tag_string;
extern int tolua_tag_userdata;
extern int tolua_tag_table;
extern int tolua_tag_function;

#ifdef __cplusplus
}
#endif

#endif