Skip to content

Commit 33c5961

Browse files
author
Ryan Nevell
committed
Fix unwrapping of LUA lightuserdata type. Add test case.
1 parent b465531 commit 33c5961

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-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+
require("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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
%module lua_lightuserdata
2+
3+
%native(get_lightuserdata) int get_lightuserdata(lua_State* L);
4+
%{
5+
int get_lightuserdata(lua_State* L)
6+
{
7+
lua_pushlightuserdata(L, reinterpret_cast<void*>(0x123456));
8+
return 1;
9+
}
10+
%}
11+
12+
%inline %{
13+
bool check_lighuserdata(const void* d) {
14+
return reinterpret_cast<void*>(0x123456) == d;
15+
}
16+
%}

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)