[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cinvoke-dev] Problem using tables in Lua callback
From: |
Bradley Smith |
Subject: |
[cinvoke-dev] Problem using tables in Lua callback |
Date: |
Wed, 23 May 2007 19:24:02 -0700 |
User-agent: |
Thunderbird 1.5.0.10 (Windows/20070221) |
On Windows, when I try to use table.insert in a Lua callback, C/Invoke
crashes. Below is an example which is a variation on an example in the
C/Invoke Lua documentation. What is going wrong?
Thanks,
Bradley
----- myfunc.c -----
// Compiled with Visual Studio 2005 command: cl /LD myfunc.c
#ifdef _WIN32
__declspec(dllexport) void myfunc(void (*cb)(int), int);
#endif
void myfunc(void (*cb)(int), int i) {
cb(i);
}
----- useMyfunc.lua -----
require("cinvoke_lua")
mylib = clibrary.new("myfunc.dll")
function lua_cb(i)
if i == 3 then
t = {}
t.value = i
print("value " .. t.value)
elseif i == 4 then
t = {}
print("crashes at next line")
table.insert(t, i)
print("value[1] = " .. t[1])
else
print(i)
end
end
myfunc = mylib:get_function(Cvoid, "myfunc", Ccallback, Cint);
cbobj = mylib:new_callback(Cvoid, lua_cb, Cint);
myfunc(cbobj, 1) -- prints "1"
myfunc(cbobj, 2) -- prints "2"
myfunc(cbobj, 3) -- prints "3"
myfunc(cbobj, 4) -- crashes
- [cinvoke-dev] Problem using tables in Lua callback,
Bradley Smith <=