cinvoke-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cinvoke-dev] Re: Problem using tables in Lua callback


From: Bradley Smith
Subject: [cinvoke-dev] Re: Problem using tables in Lua callback
Date: Thu, 24 May 2007 23:35:42 -0700
User-agent: Thunderbird 1.5.0.10 (Windows/20070221)

Thanks for the dll. After confirming that your dll also works on my setup, I figured out what the problem is. If I link to the lua5_1_2_Win32_vc8_lib.zip binaries instead of the ...dll8_lib.zip binaries, the crash occurs. Any idea why that would happen?

Thanks,
 Bradley

Will Weisser wrote:
Hmm...

$ lua5.1 bad.lua
1
2
value 3
crashes at next line
value[1] = 4

:o

Clearly something is different with my setup.  I tried compiling
cinvoke_lua.dll with VS.NET 2K5 instead of 2K3, but it still worked.
I've attached the 2K3 version of the .dll anyway if that will
help...it's statically linked with a 2K3-compiled cinvoke 1.0.
Incidentally, I'm using the include files in lua5_1_2_Win32_dll8_lib.zip
and the binaries in lua5_1_2_Win32_bin.zip off of luabinaries.
I'm stuck for now but let me know if you have any more info.

        -W.W.

-----Original Message-----
From: Bradley Smith [mailto:address@hidden Sent: Wednesday, May 23, 2007 10:24 PM
To: address@hidden
Subject: Problem using tables in Lua callback

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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]