lua-users home
lua-l archive

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


	Hi people,
	
I'm making my slow progress using luajit and ffi, and my goal was to have in the same table both the ffi symbols from a library, and new ones added. But the goal is if one wants to add a symbol that's from the library it should report an error.

Anyway I'm not getting something right here, as my __index callback is not hit everytime, although I've installed it with setmetatable. I wonder if that's not because I'm using rawset in __index to the same table.

	Here is the code (luajit), and it loads "curl", not entirely

	https://gist.github.com/898171

	And the output

	https://gist.github.com/898172

The problem is that in the following three lines (one is only needed really, but this is to demonstrate the problem)

	print( lib["curl_easy_init"] )
	print( lib["curl_easy_init"] )
	print( lib["curl_easy_init"] )

	I get the output

	cdata<void **()>: 0x00043820
	cdata<void **()>: 0x00043820
	cdata<void **()>: 0x00043820

	But I would've expected to get

	__index: returning from table <...>
                           the symbol curl_easy_init = ...

	because I cache it with rawset( t, k, v ), although that happens in _index

The way things are is that luajit has no "portable" way of knowing what symbols might be in a .dll/.so/.dylib/etc, so as soon as someone asks for them, they get "GetProcAddress/dlsym/dyld_whateveritis" - e.g. they come in lazy.

And I'm trying to make lazy "loaded" symbols to have their "seats" preserved, if someone calls their name, but still allow for others. This is simply to wrap (hence wraplib name) symbols that might be coming out of the dynamic library, and locally defined lua ones.

I'm not entirely sure whether that's good idea at all, but wanted to try and see.
	
	Thanks,
	Dimiter "malkia" Stanev.