lua-users home
lua-l archive

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


2011/8/26 Johnson Lin <arch.jslin@gmail.com>:
> Hi list, please forgive my poor english. I don't know how to precisely
> describe this issue briefly in the email subject.
>
> I read Mike's solution for writing:
>
> local SDL = ffi.load(path_to_SDL);  ffi.cdef( somehow read SDL's header );
> SDL.Init()
>
> instead of writing:
>
> local SDL = ffi.load(path_to_SDL);  ffi.cdef( somehow read SDL's header );
> SDL.SDL_Init()
>
> which uses gcc's symbol renaming functionality:
>
> ffi.cdef[[
> int Init(int) asm("SDL_Init");
> ]]
>
> because we'll want to avoid writing the namespace twice everytime when
> using LuaJIT FFI (for another instance: GL.glBegin()  <-> GL.begin()
> ). so yeah, the gcc renaming thingy is nice to have. However, when
> LibA and LibB have similar or identical naming convention, this will
> become a problem:
>
> local LibA = ffi.load(path_to_LibA)
> ffi.cdef[[
> int Init() asm("LibA_Init");
> ]]
>
> local LibB = ffi.load(path_to_LibB)
> ffi.cdef[[
> int Init() asm("LibB_Init");
> ]]
>
> I'd like to write
>
> LibA.Init()
> LibB.Init()
>
> but that's not going to happen for now, because you can have only one
> "Init". or I'll have to use
>
> LibA.Init() --renamed
> LibB.LibB_Init() -- can't rename to Init
>
> although it's very unlikely to happen, but even if we don't rename
> anything, won't there be a chance that we ffi.load() two libraries
> which already expose conflict names? Please correct me if I am wrong
> on this matter, and I'd like to know if there's any solution, or this
> feature will be in LuaJIT's future releases?
>
> Best regards,
> Johnson Lin
>
>

Maybe Mike can make something like:

local SDL = ffi.load(path_to_libSDL)
SDL.cdef [[ ... ]]

to solve this problem :)