简体   繁体   中英

lua ffi functions sharing namespace

I'm able to share the same "namespace" for two different libraries using LuaJit in Linux

A = ffi.load(ffi.os == "Windows" and "opengl32" or "GLESv2")
B = ffi.load(ffi.os == "Windows" and "glfw3" or "glfw")
C = B,A

Doing this allows me to call functions from either library from the C variable

However in windows functions in the last library A can't be found (I'm using the LuaJit binary from https://luapower.com/ )

I guess both platforms should behave the same (if it can't be done on both platforms (which would be odd) then neither platform should allow it?)

Is this a bug or is there a more robust method to do what I'm attempting?

If I'm reading the documentation correctly, then you cannot generally access all libraries through the same namespace.

On POSIX (Linux, BSD, etc.) systems, you can call ffi.load( name, true ) to make the symbols available from within ffi.C . There's no mention of this working or not working on windows, so I assume this won't work there.

That means that this is not a bug and the more robust method that you're looking for is to access symbols from different libraries through their respective library namespaces. (For your example that would mean accessing opengl functions through A and glfw functions through B .)


I guess both platforms should behave the same (if it can't be done on both platforms (which would be odd) then neither platform should allow it?)

There's tons of stuff that can be done in some way on Windows/Linux/Mac OS/BSD/…, but works completely different on some or all of them. Dynamic linking is just one of these. There's many more, including simple things like the concept of a "directory" containing files – the concept exists on all of these platforms but there's no common API, and a low-level wrapper (like LuaJIT's FFI is for dynamic linking) would likely expose some of the differences.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM