|
|
|
|
@ -630,10 +630,12 @@ SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State *L, swig_lua_namespace *
|
|
|
|
|
/* Register all classes in the namespace */
|
|
|
|
|
SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace *ns)
|
|
|
|
|
{
|
|
|
|
|
swig_lua_class **classes;
|
|
|
|
|
|
|
|
|
|
/* There must be a module/namespace table at the top of the stack */
|
|
|
|
|
assert(lua_istable(L,-1));
|
|
|
|
|
|
|
|
|
|
swig_lua_class **classes = ns->ns_classes;
|
|
|
|
|
classes = ns->ns_classes;
|
|
|
|
|
|
|
|
|
|
if( classes != 0 ) {
|
|
|
|
|
while(*classes != 0) {
|
|
|
|
|
@ -650,6 +652,7 @@ SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace
|
|
|
|
|
*/
|
|
|
|
|
SWIGINTERN void SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns, int reg)
|
|
|
|
|
{
|
|
|
|
|
swig_lua_namespace **sub_namespace;
|
|
|
|
|
/* 1 argument - table on the top of the stack */
|
|
|
|
|
const int SWIGUNUSED begin = lua_gettop(L);
|
|
|
|
|
assert(lua_istable(L,-1)); /* just in case. This is supposed to be module table or parent namespace table */
|
|
|
|
|
@ -681,7 +684,7 @@ SWIGINTERN void SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns
|
|
|
|
|
/* Register classes */
|
|
|
|
|
SWIG_Lua_add_namespace_classes(L,ns);
|
|
|
|
|
|
|
|
|
|
swig_lua_namespace **sub_namespace = ns->ns_namespaces;
|
|
|
|
|
sub_namespace = ns->ns_namespaces;
|
|
|
|
|
if( sub_namespace != 0) {
|
|
|
|
|
while(*sub_namespace != 0) {
|
|
|
|
|
SWIG_Lua_namespace_register(L, *sub_namespace, 1);
|
|
|
|
|
@ -753,22 +756,21 @@ SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info * SWIGUNUSED
|
|
|
|
|
/* first_arg - position of the object in stack. Everything that is above are arguments
|
|
|
|
|
* and is passed to every evocation of the func */
|
|
|
|
|
int last_arg = lua_gettop(L);/* position of last argument */
|
|
|
|
|
int original_metatable;
|
|
|
|
|
int original_metatable = last_arg + 1;
|
|
|
|
|
size_t bases_count;
|
|
|
|
|
int result;
|
|
|
|
|
int result = SWIG_ERROR;
|
|
|
|
|
lua_getmetatable(L,first_arg);
|
|
|
|
|
original_metatable = last_arg + 1;
|
|
|
|
|
SWIG_LUA_INIT_BASE_SEARCH(bases_count);
|
|
|
|
|
result = SWIG_ERROR;
|
|
|
|
|
if(ret)
|
|
|
|
|
*ret = 0;
|
|
|
|
|
if(bases_count>0)
|
|
|
|
|
{
|
|
|
|
|
int to_remove;
|
|
|
|
|
size_t i;
|
|
|
|
|
int j;
|
|
|
|
|
int subcall_last_arg;
|
|
|
|
|
int subcall_first_arg = lua_gettop(L) + 1;/* Here a copy of first_arg and arguments begin */
|
|
|
|
|
int valid = 1;
|
|
|
|
|
int subcall_last_arg;
|
|
|
|
|
swig_type_info *base_swig_type = 0;
|
|
|
|
|
for(j=first_arg;j<=last_arg;j++)
|
|
|
|
|
lua_pushvalue(L,j);
|
|
|
|
|
@ -792,7 +794,7 @@ SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info * SWIGUNUSED
|
|
|
|
|
lua_pushvalue(L,original_metatable);
|
|
|
|
|
lua_setmetatable(L,first_arg);
|
|
|
|
|
/* Clear - remove everything between last_arg and subcall_last_arg including */
|
|
|
|
|
const int to_remove = subcall_last_arg - last_arg;
|
|
|
|
|
to_remove = subcall_last_arg - last_arg;
|
|
|
|
|
for(j=0;j<to_remove;j++)
|
|
|
|
|
lua_remove(L,last_arg+1);
|
|
|
|
|
} else {
|
|
|
|
|
@ -813,6 +815,7 @@ SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int SW
|
|
|
|
|
(1) userdata (not the meta table)
|
|
|
|
|
(2) string name of the attribute
|
|
|
|
|
*/
|
|
|
|
|
int bases_search_result;
|
|
|
|
|
int substack_start = lua_gettop(L)-2;
|
|
|
|
|
assert(first_arg == substack_start+1);
|
|
|
|
|
lua_checkstack(L,5);
|
|
|
|
|
@ -865,11 +868,8 @@ SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int SW
|
|
|
|
|
/* Remove the metatable */
|
|
|
|
|
lua_pop(L,1);
|
|
|
|
|
/* Search in base classes */
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
int bases_search_result = SWIG_Lua_iterate_bases(L,type,substack_start+1,SWIG_Lua_class_do_get,ret);
|
|
|
|
|
return bases_search_result; /* sorry not known */
|
|
|
|
|
}
|
|
|
|
|
bases_search_result = SWIG_Lua_iterate_bases(L,type,substack_start+1,SWIG_Lua_class_do_get,ret);
|
|
|
|
|
return bases_search_result; /* sorry not known */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* the class.get method, performs the lookup of class attributes
|
|
|
|
|
@ -880,11 +880,14 @@ SWIGINTERN int SWIG_Lua_class_get(lua_State *L)
|
|
|
|
|
(1) userdata (not the meta table)
|
|
|
|
|
(2) string name of the attribute
|
|
|
|
|
*/
|
|
|
|
|
assert(lua_isuserdata(L,1));
|
|
|
|
|
swig_lua_userdata *usr=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
|
|
|
|
|
swig_type_info *type = usr->type;
|
|
|
|
|
int result;
|
|
|
|
|
swig_lua_userdata *usr;
|
|
|
|
|
swig_type_info *type;
|
|
|
|
|
int ret = 0;
|
|
|
|
|
int result = SWIG_Lua_class_do_get(L,type,1,&ret);
|
|
|
|
|
assert(lua_isuserdata(L,1));
|
|
|
|
|
usr=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
|
|
|
|
|
type = usr->type;
|
|
|
|
|
result = SWIG_Lua_class_do_get(L,type,1,&ret);
|
|
|
|
|
if(result == SWIG_OK)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
@ -902,6 +905,7 @@ SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int fi
|
|
|
|
|
(3) any for the new value
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int bases_search_result;
|
|
|
|
|
int substack_start = lua_gettop(L) - 3;
|
|
|
|
|
lua_checkstack(L,5);
|
|
|
|
|
assert(lua_isuserdata(L,substack_start+1)); /* just in case */
|
|
|
|
|
@ -944,14 +948,12 @@ SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int fi
|
|
|
|
|
lua_pop(L,1); /* remove value */
|
|
|
|
|
|
|
|
|
|
lua_pop(L,1); /* remove metatable */
|
|
|
|
|
{
|
|
|
|
|
/* Search among bases */
|
|
|
|
|
int bases_search_result = SWIG_Lua_iterate_bases(L,type,first_arg,SWIG_Lua_class_do_set,ret);
|
|
|
|
|
if(ret)
|
|
|
|
|
assert(*ret == 0);
|
|
|
|
|
assert(lua_gettop(L) == substack_start + 3);
|
|
|
|
|
return bases_search_result;
|
|
|
|
|
}
|
|
|
|
|
/* Search among bases */
|
|
|
|
|
bases_search_result = SWIG_Lua_iterate_bases(L,type,first_arg,SWIG_Lua_class_do_set,ret);
|
|
|
|
|
if(ret)
|
|
|
|
|
assert(*ret == 0);
|
|
|
|
|
assert(lua_gettop(L) == substack_start + 3);
|
|
|
|
|
return bases_search_result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This is the actual method exported to Lua. It calls SWIG_Lua_class_do_set and correctly
|
|
|
|
|
@ -964,11 +966,14 @@ SWIGINTERN int SWIG_Lua_class_set(lua_State *L)
|
|
|
|
|
(2) string name of the attribute
|
|
|
|
|
(3) any for the new value
|
|
|
|
|
*/
|
|
|
|
|
assert(lua_isuserdata(L,1));
|
|
|
|
|
swig_lua_userdata *usr=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
|
|
|
|
|
swig_type_info *type = usr->type;
|
|
|
|
|
int ret = 0;
|
|
|
|
|
int result = SWIG_Lua_class_do_set(L,type,1,&ret);
|
|
|
|
|
int result;
|
|
|
|
|
swig_lua_userdata *usr;
|
|
|
|
|
swig_type_info *type;
|
|
|
|
|
assert(lua_isuserdata(L,1));
|
|
|
|
|
usr=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
|
|
|
|
|
type = usr->type;
|
|
|
|
|
result = SWIG_Lua_class_do_set(L,type,1,&ret);
|
|
|
|
|
if(result != SWIG_OK) {
|
|
|
|
|
SWIG_Lua_pushferrstring(L,"Assignment not possible. No setter/member with this name. For custom assignments implement __setitem method.");
|
|
|
|
|
lua_error(L);
|
|
|
|
|
@ -1004,13 +1009,15 @@ SWIGINTERN int SWIG_Lua_class_tostring(lua_State *L)
|
|
|
|
|
{
|
|
|
|
|
/* there should be 1 param passed in
|
|
|
|
|
(1) userdata (not the metatable) */
|
|
|
|
|
const char *className;
|
|
|
|
|
void* userData;
|
|
|
|
|
assert(lua_isuserdata(L,1)); /* just in case */
|
|
|
|
|
void* userData = lua_touserdata(L,1); /* get the userdata address for later */
|
|
|
|
|
userData = lua_touserdata(L,1); /* get the userdata address for later */
|
|
|
|
|
lua_getmetatable(L,1); /* get the meta table */
|
|
|
|
|
assert(lua_istable(L,-1)); /* just in case */
|
|
|
|
|
|
|
|
|
|
lua_getfield(L, -1, ".type");
|
|
|
|
|
const char *className = lua_tostring(L, -1);
|
|
|
|
|
className = lua_tostring(L, -1);
|
|
|
|
|
|
|
|
|
|
lua_pushfstring(L, "<%s userdata: %p>", className, userData);
|
|
|
|
|
return 1;
|
|
|
|
|
@ -1238,10 +1245,10 @@ SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class
|
|
|
|
|
SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L, swig_lua_class *clss)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
size_t bases_count = 0;
|
|
|
|
|
/* Add bases to .bases table */
|
|
|
|
|
SWIG_Lua_get_table(L,".bases");
|
|
|
|
|
assert(lua_istable(L,-1)); /* just in case */
|
|
|
|
|
size_t bases_count = 0;
|
|
|
|
|
for(i=0;clss->bases[i];i++)
|
|
|
|
|
{
|
|
|
|
|
SWIG_Lua_get_class_metatable(L,clss->bases[i]->fqname);
|
|
|
|
|
@ -1296,7 +1303,7 @@ SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L); /*forward declaration
|
|
|
|
|
|
|
|
|
|
/* The real function that resolves a metamethod.
|
|
|
|
|
* Function searches given class and all it's bases(recursively) for first instance of something that is
|
|
|
|
|
* not equal to SWIG_Lua_resolve_metatmethod. (Almost always this 'something' is actuall metamethod implementation
|
|
|
|
|
* not equal to SWIG_Lua_resolve_metatmethod. (Almost always this 'something' is actual metamethod implementation
|
|
|
|
|
* and it is a SWIG-generated C function.). It returns value on the top of the L and there is no garbage below the
|
|
|
|
|
* answer.
|
|
|
|
|
* Returns 1 if found, 0 otherwise.
|
|
|
|
|
@ -1310,6 +1317,9 @@ SWIGINTERN int SWIG_Lua_do_resolve_metamethod(lua_State *L, const swig_lua_class
|
|
|
|
|
int skip_check)
|
|
|
|
|
{
|
|
|
|
|
/* This function is called recursively */
|
|
|
|
|
int result = 0;
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
if (!skip_check) {
|
|
|
|
|
SWIG_Lua_get_class_metatable(L, clss->fqname);
|
|
|
|
|
lua_pushvalue(L, metamethod_name_idx);
|
|
|
|
|
@ -1326,8 +1336,6 @@ SWIGINTERN int SWIG_Lua_do_resolve_metamethod(lua_State *L, const swig_lua_class
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Forwarding calls to bases */
|
|
|
|
|
int result = 0;
|
|
|
|
|
int i = 0;
|
|
|
|
|
for(i=0;clss->bases[i];i++)
|
|
|
|
|
{
|
|
|
|
|
result = SWIG_Lua_do_resolve_metamethod(L, clss->bases[i], metamethod_name_idx, 0);
|
|
|
|
|
@ -1342,21 +1350,26 @@ SWIGINTERN int SWIG_Lua_do_resolve_metamethod(lua_State *L, const swig_lua_class
|
|
|
|
|
* and calls it */
|
|
|
|
|
SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L)
|
|
|
|
|
{
|
|
|
|
|
int numargs;
|
|
|
|
|
int metamethod_name_idx;
|
|
|
|
|
const swig_lua_class* clss;
|
|
|
|
|
int result;
|
|
|
|
|
|
|
|
|
|
lua_checkstack(L,5);
|
|
|
|
|
const int numargs = lua_gettop(L); /* number of arguments to pass to actuall metamethod */
|
|
|
|
|
numargs = lua_gettop(L); /* number of arguments to pass to actual metamethod */
|
|
|
|
|
|
|
|
|
|
/* Get upvalues from closure */
|
|
|
|
|
lua_pushvalue(L, lua_upvalueindex(1)); /*Get function name*/
|
|
|
|
|
const int metamethod_name_idx = lua_gettop(L);
|
|
|
|
|
metamethod_name_idx = lua_gettop(L);
|
|
|
|
|
|
|
|
|
|
lua_pushvalue(L, lua_upvalueindex(2));
|
|
|
|
|
const swig_lua_class* clss = (const swig_lua_class*)(lua_touserdata(L,-1));
|
|
|
|
|
clss = (const swig_lua_class*)(lua_touserdata(L,-1));
|
|
|
|
|
lua_pop(L,1); /* remove lightuserdata with clss from stack */
|
|
|
|
|
|
|
|
|
|
/* Actuall work */
|
|
|
|
|
const int result = SWIG_Lua_do_resolve_metamethod(L, clss, metamethod_name_idx, 1);
|
|
|
|
|
/* Actual work */
|
|
|
|
|
result = SWIG_Lua_do_resolve_metamethod(L, clss, metamethod_name_idx, 1);
|
|
|
|
|
if (!result) {
|
|
|
|
|
SWIG_Lua_pushferrstring(L,"The metamethod proxy is set, but it failed to find actuall metamethod. Memory corruption is most likely explanation.");
|
|
|
|
|
SWIG_Lua_pushferrstring(L,"The metamethod proxy is set, but it failed to find actual metamethod. Memory corruption is most likely explanation.");
|
|
|
|
|
lua_error(L);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
@ -1374,10 +1387,14 @@ SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L)
|
|
|
|
|
*/
|
|
|
|
|
SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *clss, const int metatable_index)
|
|
|
|
|
{
|
|
|
|
|
int key_index;
|
|
|
|
|
int success = 0;
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
/* metamethod name - on the top of the stack */
|
|
|
|
|
assert(lua_isstring(L,-1));
|
|
|
|
|
|
|
|
|
|
const int key_index = lua_gettop(L);
|
|
|
|
|
key_index = lua_gettop(L);
|
|
|
|
|
|
|
|
|
|
/* Check whether method is already defined in metatable */
|
|
|
|
|
lua_pushvalue(L,key_index); /* copy of the key */
|
|
|
|
|
@ -1389,8 +1406,6 @@ SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *
|
|
|
|
|
lua_pop(L,1);
|
|
|
|
|
|
|
|
|
|
/* Iterating over immediate bases */
|
|
|
|
|
int success = 0;
|
|
|
|
|
int i = 0;
|
|
|
|
|
for(i=0;clss->bases[i];i++)
|
|
|
|
|
{
|
|
|
|
|
const swig_lua_class *base = clss->bases[i];
|
|
|
|
|
@ -1420,11 +1435,15 @@ SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *
|
|
|
|
|
|
|
|
|
|
SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class *clss)
|
|
|
|
|
{
|
|
|
|
|
int metatable_index;
|
|
|
|
|
int metamethods_info_index;
|
|
|
|
|
int tostring_undefined;
|
|
|
|
|
|
|
|
|
|
SWIG_Lua_get_class_metatable(L, clss->fqname);
|
|
|
|
|
const int metatable_index = lua_gettop(L);
|
|
|
|
|
metatable_index = lua_gettop(L);
|
|
|
|
|
SWIG_Lua_get_inheritable_metamethods(L);
|
|
|
|
|
assert(lua_istable(L,-1));
|
|
|
|
|
const int metamethods_info_index = lua_gettop(L);
|
|
|
|
|
metamethods_info_index = lua_gettop(L);
|
|
|
|
|
lua_pushnil(L); /* first key */
|
|
|
|
|
while(lua_next(L, metamethods_info_index) != 0 ) {
|
|
|
|
|
/* key at index -2, value at index -1 */
|
|
|
|
|
@ -1442,7 +1461,7 @@ SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class
|
|
|
|
|
lua_pushstring(L, "__tostring");
|
|
|
|
|
lua_pushvalue(L,-1);
|
|
|
|
|
lua_rawget(L,metatable_index);
|
|
|
|
|
const int tostring_undefined = lua_isnil(L,-1);
|
|
|
|
|
tostring_undefined = lua_isnil(L,-1);
|
|
|
|
|
lua_pop(L,1);
|
|
|
|
|
if( tostring_undefined ) {
|
|
|
|
|
lua_pushcfunction(L, SWIG_Lua_class_tostring);
|
|
|
|
|
@ -1494,6 +1513,7 @@ SWIGINTERN void SWIG_Lua_class_register_static(lua_State *L, swig_lua_class *cls
|
|
|
|
|
*/
|
|
|
|
|
SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *clss)
|
|
|
|
|
{
|
|
|
|
|
int new_metatable_index;
|
|
|
|
|
const int SWIGUNUSED begin = lua_gettop(L);
|
|
|
|
|
int i;
|
|
|
|
|
/* if name already there (class is already registered) then do nothing */
|
|
|
|
|
@ -1520,11 +1540,12 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c
|
|
|
|
|
* It would get us all special methods: __getitem, __add etc.
|
|
|
|
|
* This would set .fn, .type, and other .xxx incorrectly, but we will overwrite it right away
|
|
|
|
|
*/
|
|
|
|
|
const int new_metatable_index = lua_absindex(L,-1);
|
|
|
|
|
new_metatable_index = lua_absindex(L,-1);
|
|
|
|
|
for(i=0;clss->bases[i];i++)
|
|
|
|
|
{
|
|
|
|
|
int base_metatable;
|
|
|
|
|
SWIG_Lua_get_class_metatable(L,clss->bases[i]->fqname);
|
|
|
|
|
const int base_metatable = lua_absindex(L,-1);
|
|
|
|
|
base_metatable = lua_absindex(L,-1);
|
|
|
|
|
SWIG_Lua_merge_tables_by_index(L,new_metatable_index, base_metatable);
|
|
|
|
|
lua_pop(L,1);
|
|
|
|
|
}
|
|
|
|
|
@ -1573,6 +1594,7 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c
|
|
|
|
|
|
|
|
|
|
SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss)
|
|
|
|
|
{
|
|
|
|
|
int SWIGUNUSED begin;
|
|
|
|
|
assert(lua_istable(L,-1)); /* This is a table (module or namespace) where classes will be added */
|
|
|
|
|
SWIG_Lua_class_register_instance(L,clss);
|
|
|
|
|
SWIG_Lua_class_register_static(L,clss);
|
|
|
|
|
@ -1587,7 +1609,7 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss)
|
|
|
|
|
* | ".set" --> ....
|
|
|
|
|
* |=============================== ".instance"
|
|
|
|
|
*/
|
|
|
|
|
const int SWIGUNUSED begin = lua_gettop(L);
|
|
|
|
|
begin = lua_gettop(L);
|
|
|
|
|
lua_pushstring(L,clss->cls_static->name);
|
|
|
|
|
lua_rawget(L,-2); /* get class static table */
|
|
|
|
|
assert(lua_istable(L,-1));
|
|
|
|
|
|