lua-users home
lua-l archive

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


On Sun, Jan 15, 2012 at 10:21, Duncan Cross <duncan.cross@gmail.com> wrote:
> On Sun, Jan 15, 2012 at 2:48 PM, Leo Razoumov <slonik.az@gmail.com> wrote:
>> 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?
>
> See the FFI Semantics section on callbacks:
> http://luajit.org/ext_ffi_semantics.html#callback
>
> (Ordinarily of course, you wouldn't call the created callback yourself
> from Lua -- I just did that for minimal demonstration purposes. I can
> confirm the same thing happens when it gets called from C.)
>

I thought that FFI callbacks were exclusively for calling Lua
functions from within C-code using function pointers. It never
occurred to me that a FFI cdata functor created via ffi.cast is
callable from within Lua. Neat!

--Leo--