lua-users home
lua-l archive

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


Hi Mike,

__index and __newindex are only called if the corresponding table
entry doesn't exist (i.e. is nil). As soon as a non-nil value
exists for a key, no metamethods are called on reads or writes.

May I suggest you (re)read "Programming in Lua". :-)

I will. This is the first time I went into metatables, and was expecting them to behave in a way that I totally made up myself.

Actually if __index and __newindex were working like the way I wanted, it probably would've been slower to optimize (calling __index everytime - bad idea I guess).

	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.

Well no, I don't think this is a good idea. First: I wouldn't
bother with lazy loading -- libcurl doesn't have that many
symbols. And second: I cannot see any reason why a user of a
library would behave that way and why you go to these lengths
trying to forbid this.

I wanted to provide raw ffi access, and then complement them with helper functions dealing and returning lua objects and sometimes ffi handles. CURL was given as simple example, my goal is OpenCL/GL/etc. - and I wrote couple of helper functions for OpenCL to return in lua tables the relevant information.

I wanted them to live in the same table, but now I'm realizing that's not a good idea, especially when it got me itself confused, and had to produce more code (metatables) and it's no longer simple.

I'll just provide two tables, one returned by ffi.load which in fact is userdata, not table, and another for additional helper functions to the related API.

Thinking more about it, these helper functions should be in a separate file, as they might not be useful for everyone, but the FFI bindings most likely will.

I mean, anyone can write math.sin = math.random -- yeah, that's a
bad idea, but so what? It's the user's problem, if they do such
nonsense.

Thanks Mike, that was very helpful!

Cheers,
Dimiter "malkia" Stanev.