LuaRef and tables

A LuaRef variable can point to any type of data—even a table! When a LuaRef variable points to a table, it can be indexed very naturally using brackets ([]). Consider the following Lua code:

velocity = {
x = 7,
y = 0,
units = "miles"
}

velocity.debug = function()
print (velocity.x .. ", " .. velocity.y .. " " .. units .. " / hour")
end

We can access, and even change, any variable located in the velocity table by using a LuaRef object. The following code sample demonstrates this:

LuaRef v = getGlobal(L, "velocity");
v["y"] = 6
v["units"] = "km"

v["debug"]();
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.45.5