mirror of https://github.com/swig/swig
Apply #3219676 from Shane Liesegang which adds: - support for %factory - a __tostring method - a __disown method
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12978 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
39d8882a82
commit
5c8e5542ef
|
@ -5,6 +5,12 @@ See the RELEASENOTES file for a summary of changes in each release.
|
||||||
Version 2.0.5 (in progress)
|
Version 2.0.5 (in progress)
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
2012-04-13: wsfulton
|
||||||
|
[Lua] Apply #3219676 from Shane Liesegang which adds:
|
||||||
|
- support for %factory
|
||||||
|
- a __tostring method
|
||||||
|
- a __disown method
|
||||||
|
|
||||||
2012-04-13: wsfulton
|
2012-04-13: wsfulton
|
||||||
[Xml] Apply #3513569 which adds a catchlist to the xml output.
|
[Xml] Apply #3513569 which adds a catchlist to the xml output.
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,12 @@
|
||||||
_a = disown;
|
_a = disown;
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int remove(A *remove)
|
||||||
|
{
|
||||||
|
delete remove;
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,3 +12,9 @@ for x=0,100 do
|
||||||
b:acquire(a)
|
b:acquire(a)
|
||||||
end
|
end
|
||||||
collectgarbage() -- this will double delete unless the memory is managed properly
|
collectgarbage() -- this will double delete unless the memory is managed properly
|
||||||
|
|
||||||
|
a=disown.A()
|
||||||
|
a:__disown()
|
||||||
|
b:remove(a)
|
||||||
|
a=nil
|
||||||
|
collectgarbage() -- this will double delete unless the manual disown call worked
|
||||||
|
|
|
@ -469,6 +469,39 @@ SWIGINTERN int SWIG_Lua_class_destruct(lua_State* L)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* the class.__tostring method called by the interpreter and print */
|
||||||
|
SWIGINTERN int SWIG_Lua_class_tostring(lua_State* L)
|
||||||
|
{
|
||||||
|
/* there should be 1 param passed in
|
||||||
|
(1) userdata (not the metatable) */
|
||||||
|
assert(lua_isuserdata(L,1)); /* just in case */
|
||||||
|
unsigned long userData = (unsigned long)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);
|
||||||
|
|
||||||
|
char output[256];
|
||||||
|
sprintf(output, "<%s userdata: %lX>", className, userData);
|
||||||
|
|
||||||
|
lua_pushstring(L, (const char*)output);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* to manually disown some userdata */
|
||||||
|
SWIGINTERN int SWIG_Lua_class_disown(lua_State* L)
|
||||||
|
{
|
||||||
|
/* there should be 1 params passed in
|
||||||
|
(1) userdata (not the meta table) */
|
||||||
|
swig_lua_userdata* usr;
|
||||||
|
assert(lua_isuserdata(L,-1)); /* just in case */
|
||||||
|
usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */
|
||||||
|
|
||||||
|
usr->own = 0; /* clear our ownership */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* gets the swig class registry (or creates it) */
|
/* gets the swig class registry (or creates it) */
|
||||||
SWIGINTERN void SWIG_Lua_get_class_registry(lua_State* L)
|
SWIGINTERN void SWIG_Lua_get_class_registry(lua_State* L)
|
||||||
{
|
{
|
||||||
|
@ -594,11 +627,15 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss)
|
||||||
/* add a table called ".fn" */
|
/* add a table called ".fn" */
|
||||||
lua_pushstring(L,".fn");
|
lua_pushstring(L,".fn");
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
/* add manual disown method */
|
||||||
|
SWIG_Lua_add_function(L,"__disown",SWIG_Lua_class_disown);
|
||||||
lua_rawset(L,-3);
|
lua_rawset(L,-3);
|
||||||
/* add accessor fns for using the .get,.set&.fn */
|
/* add accessor fns for using the .get,.set&.fn */
|
||||||
SWIG_Lua_add_function(L,"__index",SWIG_Lua_class_get);
|
SWIG_Lua_add_function(L,"__index",SWIG_Lua_class_get);
|
||||||
SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_class_set);
|
SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_class_set);
|
||||||
SWIG_Lua_add_function(L,"__gc",SWIG_Lua_class_destruct);
|
SWIG_Lua_add_function(L,"__gc",SWIG_Lua_class_destruct);
|
||||||
|
/* add tostring method for better output */
|
||||||
|
SWIG_Lua_add_function(L,"__tostring",SWIG_Lua_class_tostring);
|
||||||
/* add it */
|
/* add it */
|
||||||
lua_rawset(L,-3); /* metatable into registry */
|
lua_rawset(L,-3); /* metatable into registry */
|
||||||
lua_pop(L,1); /* tidy stack (remove registry) */
|
lua_pop(L,1); /* tidy stack (remove registry) */
|
||||||
|
|
Loading…
Reference in New Issue