lua-users home
lua-l archive

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

> You should probably model C structures with Lua tables (or the
> as-yet-undocumented proxies, which look to be quite nice). Then the
> is much simpler because you can define metamethods for the proxy
> tables/proxies without worrying about the global namespace at all.
No,no... I was to structs internal to C containing data about exported
(scalar) C vars,like memory pointer,type,flags etc.Regarding those
proxies though:I looked in google for lua and proxies,and having found
nothing, assumed they were not a lua feature.Is there any
(unofficial/incomplete/whatever) info on them?
> However, scalar C proxies still strike me as an interesting
question. So
> here is another solution.
> To pull this off, you need to at least associate a known metatable 
This looks like much more trouble than it has to be to me.
I just finished with the following:

local g=getglobals()
local m={				--the new globals metatable
		local cvar=cvartab[k];
		if cvar~=nil then	--a C symbol
		else			--a new lua symbol
			rawset (t,k,v)
		local cvar=cvartab[k];

		if cvar~=nil then        --a C symbol
			return getcvar(cvar)
		else			--undefined symbol
			return nil


the cvartab table is created and filled via C a functions and holds
the structs with info I was talking about.getcvar/setcvar are simple C
functions to get/set the vars.This is more or less what Pter said.Will
it be slower than your method?BTW I meant to ask you guys.How are
table lookups implemented in lua.I was thinking wether it would be
(significantly)faster to store the info about cvars in an internal C
hash table for the lookups.Would there be any difference?I don't
think so.