00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "tolua++.h"
00015 #include "lauxlib.h"
00016
00017 #include <stdlib.h>
00018
00019 TOLUA_API void tolua_pushvalue (lua_State* L, int lo)
00020 {
00021 lua_pushvalue(L,lo);
00022 }
00023
00024 TOLUA_API void tolua_pushboolean (lua_State* L, int value)
00025 {
00026 lua_pushboolean(L,value);
00027 }
00028
00029 TOLUA_API void tolua_pushnumber (lua_State* L, double value)
00030 {
00031 lua_pushnumber(L,value);
00032 }
00033
00034 TOLUA_API void tolua_pushstring (lua_State* L, const char* value)
00035 {
00036 if (value == NULL)
00037 lua_pushnil(L);
00038 else
00039 lua_pushstring(L,value);
00040 }
00041
00042 TOLUA_API void tolua_pushuserdata (lua_State* L, void* value)
00043 {
00044 if (value == NULL)
00045 lua_pushnil(L);
00046 else
00047 lua_pushlightuserdata(L,value);
00048 }
00049
00050 TOLUA_API void tolua_pushusertype (lua_State* L, void* value, const char* type)
00051 {
00052 if (value == NULL)
00053 lua_pushnil(L);
00054 else
00055 {
00056 luaL_getmetatable(L, type);
00057 lua_pushstring(L,"tolua_ubox");
00058 lua_rawget(L,-2);
00059 if (lua_isnil(L, -1)) {
00060 lua_pop(L, 1);
00061 lua_pushstring(L, "tolua_ubox");
00062 lua_rawget(L, LUA_REGISTRYINDEX);
00063 };
00064 lua_pushlightuserdata(L,value);
00065 lua_rawget(L,-2);
00066 if (lua_isnil(L,-1))
00067 {
00068 lua_pop(L,1);
00069 lua_pushlightuserdata(L,value);
00070 *(void**)lua_newuserdata(L,sizeof(void *)) = value;
00071 lua_pushvalue(L,-1);
00072 lua_insert(L,-4);
00073 lua_rawset(L,-3);
00074 lua_pop(L,1);
00075
00076 lua_pushvalue(L, -2);
00077 lua_setmetatable(L,-2);
00078
00079 #ifdef LUA_VERSION_NUM
00080 lua_pushvalue(L, TOLUA_NOPEER);
00081 lua_setfenv(L, -2);
00082 #endif
00083 }
00084 else
00085 {
00086
00087 lua_insert(L,-2);
00088 lua_pop(L,1);
00089 lua_pushstring(L,"tolua_super");
00090 lua_rawget(L,LUA_REGISTRYINDEX);
00091 lua_getmetatable(L,-2);
00092 lua_rawget(L,-2);
00093 if (lua_istable(L,-1))
00094 {
00095 lua_pushstring(L,type);
00096 lua_rawget(L,-2);
00097 if (lua_toboolean(L,-1) == 1)
00098 {
00099 lua_pop(L,3);
00100 lua_remove(L, -2);
00101 return;
00102 }
00103 }
00104
00105
00106 lua_pushvalue(L, -5);
00107 lua_setmetatable(L,-5);
00108 lua_pop(L,3);
00109 }
00110 lua_remove(L, -2);
00111 }
00112 }
00113
00114 TOLUA_API void tolua_pushusertype_and_takeownership (lua_State* L, void* value, const char* type)
00115 {
00116 tolua_pushusertype(L,value,type);
00117 tolua_register_gc(L,lua_gettop(L));
00118 }
00119
00120 TOLUA_API void tolua_pushfieldvalue (lua_State* L, int lo, int index, int v)
00121 {
00122 lua_pushnumber(L,index);
00123 lua_pushvalue(L,v);
00124 lua_settable(L,lo);
00125 }
00126
00127 TOLUA_API void tolua_pushfieldboolean (lua_State* L, int lo, int index, int v)
00128 {
00129 lua_pushnumber(L,index);
00130 lua_pushboolean(L,v);
00131 lua_settable(L,lo);
00132 }
00133
00134
00135 TOLUA_API void tolua_pushfieldnumber (lua_State* L, int lo, int index, double v)
00136 {
00137 lua_pushnumber(L,index);
00138 tolua_pushnumber(L,v);
00139 lua_settable(L,lo);
00140 }
00141
00142 TOLUA_API void tolua_pushfieldstring (lua_State* L, int lo, int index, const char* v)
00143 {
00144 lua_pushnumber(L,index);
00145 tolua_pushstring(L,v);
00146 lua_settable(L,lo);
00147 }
00148
00149 TOLUA_API void tolua_pushfielduserdata (lua_State* L, int lo, int index, void* v)
00150 {
00151 lua_pushnumber(L,index);
00152 tolua_pushuserdata(L,v);
00153 lua_settable(L,lo);
00154 }
00155
00156 TOLUA_API void tolua_pushfieldusertype (lua_State* L, int lo, int index, void* v, const char* type)
00157 {
00158 lua_pushnumber(L,index);
00159 tolua_pushusertype(L,v,type);
00160 lua_settable(L,lo);
00161 }
00162
00163 TOLUA_API void tolua_pushfieldusertype_and_takeownership (lua_State* L, int lo, int index, void* v, const char* type)
00164 {
00165 lua_pushnumber(L,index);
00166 tolua_pushusertype(L,v,type);
00167 tolua_register_gc(L,lua_gettop(L));
00168 lua_settable(L,lo);
00169 }
00170