lua-users home
lua-l archive

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


> There's a perfectly suitable Lua feature for generating all kinds
> of namespaces of your own: a proxy table, i.e. a table with a
> metatable and __index/__newindex methods. You could also use
> newproxy(), which is slightly more efficient, unless you want to
> put extra symbols into the proxy table.

You are absolutely right (as usual :>). And thanks for pointing out 'newproxy()'.

Peeking into lj_clib.c I can see that the library itself is kind of table with __index that does dlsym only if there's no symbol yet cached and stores it into cache table.

So using my own proxy with __index and rawset basically will mimic this behavior, calling function 1st time, pointer will be cached with key having library name prefix removed, avoiding calling __index all over again.

Will LJ2 be able to hoist the subsequent function calls hash table lookups out if I do it that way?

> Sadly, the underlying OS APIs (e.g. dlopen/dlsym) do not support
> such a functionality. You'd need to probe all symbols or dive down
> into the OS-specific file formats of shared libraries (and handle
> all the name mangling that the dynamic loader does on its own, too).

Just browsed little more about that and it seems LJ would need to parse ELF, PE, Mach-O to get these. But I guess this could be done by Lua + FFI. No need to put it inside LJ.

Cheers,
-- 
Adam