[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: luaffi/luaffi question: Calling c function ptr possible?
- From: Björn Kalkbrenner <terminar@...>
- Date: Fri, 10 Jul 2015 10:32:55 +0200
Hi,
i have a question regarding the use of luaffi
(https://github.com/jmckaskill/luaffi) and since i have read this
mailinglist silently the last months the answers given to questions were
really quite helpful, it's a great list - thanks to the contributors.
Maybe someone is here using luaffi or luajit/ffi (if the differences to
luajit isn't that big) who can give me a direction. The OS is Windows.
I am creating a library which is dynamically loaded by another host
process. I have no control over the host process and the API is fixed.
This host process calls functions in my library receiving a function
pointer as argument (to return results async) and some struct memory
adresses. My function adds these values to the lua stack and executes a
lua script with lua_pcall. In other words, i am mapping calls to the
library directly to lua-functions in my script.
Currently i am using luaffi in my script calling win32 API functions and
working with the structs which is working great, the last thing which i
have not yet resolved is calling the given callback which i have
received as function pointer.
Can i cast a function pointer to something luaffi interprets as callable
function?
I have tried this (snipped out of the code):
======================================================================
ffi.cdef[[
typedef void (__stdcall *RESULT_CB)(DWORD ResultID,LONG Result);
]]
function libraryFunctionXYZ(data)
local _cb = =ffi.cast("RESULT_CB*",data.cbAddr)
_cb(0,0);
end
=====================================================================
That doesn't work, i am getting the error:
"only function callbacks are callable"
Is it even possible to cast a function pointer memory address to
something luaffi can understand/call?
Bye
Björn