| 1 |
/* tolua |
| 2 |
** Support code for Lua bindings. |
| 3 |
** Written by Waldemar Celes |
| 4 |
** TeCGraf/PUC-Rio |
| 5 |
** Apr 2003 |
| 6 |
*/ |
| 7 |
|
| 8 |
/* This code is free software; you can redistribute it and/or modify it. |
| 9 |
** The software provided hereunder is on an "as is" basis, and |
| 10 |
** the author has no obligation to provide maintenance, support, updates, |
| 11 |
** enhancements, or modifications. |
| 12 |
*/ |
| 13 |
|
| 14 |
|
| 15 |
#ifndef TOLUA_H |
| 16 |
#define TOLUA_H |
| 17 |
|
| 18 |
#ifndef TOLUA_API |
| 19 |
#define TOLUA_API extern |
| 20 |
#endif |
| 21 |
|
| 22 |
#define TOLUA_VERSION "tolua++-1.0.92" |
| 23 |
|
| 24 |
#ifdef __cplusplus |
| 25 |
extern "C" { |
| 26 |
#endif |
| 27 |
|
| 28 |
#define tolua_pushcppstring(x,y) tolua_pushstring(x,y.c_str()) |
| 29 |
#define tolua_iscppstring tolua_isstring |
| 30 |
|
| 31 |
#define tolua_iscppstringarray tolua_isstringarray |
| 32 |
#define tolua_pushfieldcppstring(L,lo,idx,s) tolua_pushfieldstring(L, lo, idx, s.c_str()) |
| 33 |
|
| 34 |
#ifndef TEMPLATE_BIND |
| 35 |
#define TEMPLATE_BIND(p) |
| 36 |
#endif |
| 37 |
|
| 38 |
#define TOLUA_TEMPLATE_BIND(p) |
| 39 |
|
| 40 |
#define TOLUA_PROTECTED_DESTRUCTOR |
| 41 |
#define TOLUA_PROPERTY_TYPE(p) |
| 42 |
|
| 43 |
typedef int lua_Object; |
| 44 |
|
| 45 |
#include "lua.h" |
| 46 |
#include "lauxlib.h" |
| 47 |
|
| 48 |
struct tolua_Error |
| 49 |
{ |
| 50 |
int index; |
| 51 |
int array; |
| 52 |
const char* type; |
| 53 |
}; |
| 54 |
typedef struct tolua_Error tolua_Error; |
| 55 |
|
| 56 |
#define TOLUA_NOPEER LUA_REGISTRYINDEX /* for lua 5.1 */ |
| 57 |
|
| 58 |
TOLUA_API const char* tolua_typename (lua_State* L, int lo); |
| 59 |
TOLUA_API void tolua_error (lua_State* L, const char* msg, tolua_Error* err); |
| 60 |
TOLUA_API int tolua_isnoobj (lua_State* L, int lo, tolua_Error* err); |
| 61 |
TOLUA_API int tolua_isvalue (lua_State* L, int lo, int def, tolua_Error* err); |
| 62 |
TOLUA_API int tolua_isvaluenil (lua_State* L, int lo, tolua_Error* err); |
| 63 |
TOLUA_API int tolua_isboolean (lua_State* L, int lo, int def, tolua_Error* err); |
| 64 |
TOLUA_API int tolua_isnumber (lua_State* L, int lo, int def, tolua_Error* err); |
| 65 |
TOLUA_API int tolua_isstring (lua_State* L, int lo, int def, tolua_Error* err); |
| 66 |
TOLUA_API int tolua_istable (lua_State* L, int lo, int def, tolua_Error* err); |
| 67 |
TOLUA_API int tolua_isusertable (lua_State* L, int lo, const char* type, int def, tolua_Error* err); |
| 68 |
TOLUA_API int tolua_isuserdata (lua_State* L, int lo, int def, tolua_Error* err); |
| 69 |
TOLUA_API int tolua_isusertype (lua_State* L, int lo, const char* type, int def, tolua_Error* err); |
| 70 |
TOLUA_API int tolua_isvaluearray |
| 71 |
(lua_State* L, int lo, int dim, int def, tolua_Error* err); |
| 72 |
TOLUA_API int tolua_isbooleanarray |
| 73 |
(lua_State* L, int lo, int dim, int def, tolua_Error* err); |
| 74 |
TOLUA_API int tolua_isnumberarray |
| 75 |
(lua_State* L, int lo, int dim, int def, tolua_Error* err); |
| 76 |
TOLUA_API int tolua_isstringarray |
| 77 |
(lua_State* L, int lo, int dim, int def, tolua_Error* err); |
| 78 |
TOLUA_API int tolua_istablearray |
| 79 |
(lua_State* L, int lo, int dim, int def, tolua_Error* err); |
| 80 |
TOLUA_API int tolua_isuserdataarray |
| 81 |
(lua_State* L, int lo, int dim, int def, tolua_Error* err); |
| 82 |
TOLUA_API int tolua_isusertypearray |
| 83 |
(lua_State* L, int lo, const char* type, int dim, int def, tolua_Error* err); |
| 84 |
|
| 85 |
TOLUA_API void tolua_open (lua_State* L); |
| 86 |
|
| 87 |
TOLUA_API void* tolua_copy (lua_State* L, void* value, unsigned int size); |
| 88 |
TOLUA_API int tolua_register_gc (lua_State* L, int lo); |
| 89 |
TOLUA_API int tolua_default_collect (lua_State* tolua_S); |
| 90 |
|
| 91 |
TOLUA_API void tolua_usertype (lua_State* L, const char* type); |
| 92 |
TOLUA_API void tolua_beginmodule (lua_State* L, const char* name); |
| 93 |
TOLUA_API void tolua_endmodule (lua_State* L); |
| 94 |
TOLUA_API void tolua_module (lua_State* L, const char* name, int hasvar); |
| 95 |
TOLUA_API void tolua_class (lua_State* L, const char* name, const char* base); |
| 96 |
TOLUA_API void tolua_cclass (lua_State* L, const char* lname, const char* name, const char* base, lua_CFunction col); |
| 97 |
TOLUA_API void tolua_function (lua_State* L, const char* name, lua_CFunction func); |
| 98 |
TOLUA_API void tolua_constant (lua_State* L, const char* name, lua_Number value); |
| 99 |
TOLUA_API void tolua_variable (lua_State* L, const char* name, lua_CFunction get, lua_CFunction set); |
| 100 |
TOLUA_API void tolua_array (lua_State* L,const char* name, lua_CFunction get, lua_CFunction set); |
| 101 |
|
| 102 |
/* TOLUA_API void tolua_set_call_event(lua_State* L, lua_CFunction func, char* type); */ |
| 103 |
/* TOLUA_API void tolua_addbase(lua_State* L, char* name, char* base); */ |
| 104 |
|
| 105 |
TOLUA_API void tolua_pushvalue (lua_State* L, int lo); |
| 106 |
TOLUA_API void tolua_pushboolean (lua_State* L, int value); |
| 107 |
TOLUA_API void tolua_pushnumber (lua_State* L, lua_Number value); |
| 108 |
TOLUA_API void tolua_pushstring (lua_State* L, const char* value); |
| 109 |
TOLUA_API void tolua_pushuserdata (lua_State* L, void* value); |
| 110 |
TOLUA_API void tolua_pushusertype (lua_State* L, void* value, const char* type); |
| 111 |
TOLUA_API void tolua_pushusertype_and_takeownership(lua_State* L, void* value, const char* type); |
| 112 |
TOLUA_API void tolua_pushfieldvalue (lua_State* L, int lo, int index, int v); |
| 113 |
TOLUA_API void tolua_pushfieldboolean (lua_State* L, int lo, int index, int v); |
| 114 |
TOLUA_API void tolua_pushfieldnumber (lua_State* L, int lo, int index, lua_Number v); |
| 115 |
TOLUA_API void tolua_pushfieldstring (lua_State* L, int lo, int index, const char* v); |
| 116 |
TOLUA_API void tolua_pushfielduserdata (lua_State* L, int lo, int index, void* v); |
| 117 |
TOLUA_API void tolua_pushfieldusertype (lua_State* L, int lo, int index, void* v, const char* type); |
| 118 |
TOLUA_API void tolua_pushfieldusertype_and_takeownership (lua_State* L, int lo, int index, void* v, const char* type); |
| 119 |
|
| 120 |
TOLUA_API lua_Number tolua_tonumber (lua_State* L, int narg, lua_Number def); |
| 121 |
TOLUA_API const char* tolua_tostring (lua_State* L, int narg, const char* def); |
| 122 |
TOLUA_API void* tolua_touserdata (lua_State* L, int narg, void* def); |
| 123 |
TOLUA_API void* tolua_tousertype (lua_State* L, int narg, void* def); |
| 124 |
TOLUA_API int tolua_tovalue (lua_State* L, int narg, int def); |
| 125 |
TOLUA_API int tolua_toboolean (lua_State* L, int narg, int def); |
| 126 |
TOLUA_API lua_Number tolua_tofieldnumber (lua_State* L, int lo, int index, lua_Number def); |
| 127 |
TOLUA_API const char* tolua_tofieldstring (lua_State* L, int lo, int index, const char* def); |
| 128 |
TOLUA_API void* tolua_tofielduserdata (lua_State* L, int lo, int index, void* def); |
| 129 |
TOLUA_API void* tolua_tofieldusertype (lua_State* L, int lo, int index, void* def); |
| 130 |
TOLUA_API int tolua_tofieldvalue (lua_State* L, int lo, int index, int def); |
| 131 |
TOLUA_API int tolua_getfieldboolean (lua_State* L, int lo, int index, int def); |
| 132 |
|
| 133 |
TOLUA_API void tolua_dobuffer(lua_State* L, char* B, unsigned int size, const char* name); |
| 134 |
|
| 135 |
TOLUA_API int class_gc_event (lua_State* L); |
| 136 |
|
| 137 |
#ifdef __cplusplus |
| 138 |
static inline const char* tolua_tocppstring (lua_State* L, int narg, const char* def) { |
| 139 |
|
| 140 |
const char* s = tolua_tostring(L, narg, def); |
| 141 |
return s?s:""; |
| 142 |
}; |
| 143 |
|
| 144 |
static inline const char* tolua_tofieldcppstring (lua_State* L, int lo, int index, const char* def) { |
| 145 |
|
| 146 |
const char* s = tolua_tofieldstring(L, lo, index, def); |
| 147 |
return s?s:""; |
| 148 |
}; |
| 149 |
|
| 150 |
#else |
| 151 |
#define tolua_tocppstring tolua_tostring |
| 152 |
#define tolua_tofieldcppstring tolua_tofieldstring |
| 153 |
#endif |
| 154 |
|
| 155 |
TOLUA_API int tolua_fast_isa(lua_State *L, int mt_indexa, int mt_indexb, int super_index); |
| 156 |
|
| 157 |
#ifndef Mtolua_new |
| 158 |
#define Mtolua_new(EXP) new EXP |
| 159 |
#endif |
| 160 |
|
| 161 |
#ifndef Mtolua_delete |
| 162 |
#define Mtolua_delete(EXP) delete EXP |
| 163 |
#endif |
| 164 |
|
| 165 |
#ifndef Mtolua_new_dim |
| 166 |
#define Mtolua_new_dim(EXP, len) new EXP[len] |
| 167 |
#endif |
| 168 |
|
| 169 |
#ifndef Mtolua_delete_dim |
| 170 |
#define Mtolua_delete_dim(EXP) delete [] EXP |
| 171 |
#endif |
| 172 |
|
| 173 |
#ifndef tolua_outside |
| 174 |
#define tolua_outside |
| 175 |
#endif |
| 176 |
|
| 177 |
#ifndef tolua_owned |
| 178 |
#define tolua_owned |
| 179 |
#endif |
| 180 |
|
| 181 |
#ifdef __cplusplus |
| 182 |
} |
| 183 |
#endif |
| 184 |
|
| 185 |
#endif |