Skip to content

Commit aad4303

Browse files
committed
Merge branch 'ryannevell-master'
* ryannevell-master: Clean up test cases Fix unwrapping of LUA lightuserdata type. Add test case.
2 parents 4ce77ff + 1860881 commit aad4303

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

Examples/test-suite/lua/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ top_builddir = @top_builddir@
1515
CPP_TEST_CASES += \
1616
lua_no_module_global \
1717
lua_inherit_getitem \
18+
lua_lightuserdata \
1819

1920

2021
C_TEST_CASES += \
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require("import") -- the import fn
2+
import("lua_lightuserdata") -- import lib
3+
4+
local t = lua_lightuserdata
5+
local d = t.get_lightuserdata()
6+
local r = t.check_lighuserdata(d)
7+
assert(r)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
%module lua_lightuserdata
2+
3+
%native(get_lightuserdata) int get_lightuserdata(lua_State* L);
4+
%{
5+
static int foo;
6+
int get_lightuserdata(lua_State* L)
7+
{
8+
lua_pushlightuserdata(L, &foo);
9+
return 1;
10+
}
11+
%}
12+
13+
%inline %{
14+
bool check_lighuserdata(const void* d) {
15+
return d == &foo;
16+
}
17+
%}

Lib/lua/luarun.swg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,11 @@ SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State *L,int index,void **ptr,swig_type
17651765
*ptr=0;
17661766
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
17671767
}
1768+
if (lua_islightuserdata(L,index))
1769+
{
1770+
*ptr=lua_touserdata(L,index);
1771+
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
1772+
}
17681773
usr=(swig_lua_userdata*)lua_touserdata(L,index); /* get data */
17691774
if (usr)
17701775
{

0 commit comments

Comments
 (0)