lua-users home
lua-l archive

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


On Sat, Jan 14, 2012 at 16:28, Duncan Cross <duncan.cross@gmail.com> wrote:
> Just discovered this (running on Windows 7):
>
> LuaJIT 2.0.0-beta9 -- Copyright (C) 2005-2011 Mike Pall. http://luajit.org/
> JIT: ON CMOV SSE2 SSE3 SSE4.1 fold cse dce fwd dse narrow loop abc fuse
>> ffi = require 'ffi'
>> func = ffi.cast('int(*)()', function()  return string.byte 'a';  end)
>> =func()
>
> (...CRASH!!)
>
> Forcing a non-tailcall fixes it:
>
> LuaJIT 2.0.0-beta9 -- Copyright (C) 2005-2011 Mike Pall. http://luajit.org/
> JIT: ON CMOV SSE2 SSE3 SSE4.1 fold cse dce fwd dse narrow loop abc fuse
>> ffi = require 'ffi'
>> func = ffi.cast('int(*)()', function()  return (string.byte 'a');  end)
>> =func()
> 97
>
> -Duncan


I confirm the same behavior on Linux (Ubuntu-10.04, LuaJIT-2.0.beta9).
On the other hand, casting a Lua-function into a C-function does not
seem to make much sense.  Can it lead to an undefined behavior?

--Leo--