Wednesday, 15 August 2012

lua - Pointer to number -



lua - Pointer to number -

it seems there's know such thing reference number/boolean/lightuserdata in lua. however, easiest way set global in lua points c++ native type (e.g. float) , have update automatically when alter corresponding global in lua?

class="lang-c prettyprint-override">int foo = 2; //imaginary lua function want lua_pushnumberpointer(state,&foo) lua_setglobal(state,"foo") class="lang-lua prettyprint-override">-- later, in lua script foo = 5;

the lastly line should automatically update foo on c++ side. easiest way accomplish this?

take @ meta tables, tags __index , __newindex. if set them suitable functions, have total command happens when new index set / unset index queried.

that should allow asked for.

it might advantageous set __newindex custom function , save interesting entries in table set on __index.

example handler __newindex , companion definition of __index. consider implementing on native side though, performance, , because __hidden_notify_world() native.

do local meta = getmetatable(_env) or {} setmetatable(_env, meta) local backing = {} _env.__index = backing function _env:__newindex(k, v) if backing[k] ~= v backing[k] = v __hidden_do_notify_world(k, v) end end end

if using lua < 5.2 (2011), must utilize _g instead of _env.

lua lua-api

No comments:

Post a Comment