It looks like you're new here. If you want to get involved, click one of these buttons!
-- ------------------------------------------------------------------ -- Declare a global table of "constants" that can't be changed once set! const = {} local data = {} const_mt = { __newindex = function(a,b,c) if data[b] == nil then if type(c) == 'table' then -- make that table readonly local proxy = {} local mt = { -- create metatable __index = c, __newindex = function (t,k,v) error("Attempt to update read-only table '"..b.."' index '"..tostring(k).."' with '"..tostring(v).."'",2) --print("Attempt to update read-only table '"..b.."' index '"..tostring(k).."' with '"..tostring(v).."'") end } setmetatable(proxy, mt) data[b]=proxy else data[b]=c end else error("Illegal assignment to constant '"..tostring(b).."'",2) --print("illegal assignment to constant '"..tostring(b).."'") end end, __index = function(a,b) return data[b] end } setmetatable(const, const_mt) |
const.GLV_STATE_NOT_INIT = 0 const.GLV_STATE_WAITING = 1 const.GLV_STATE_DL_ERROR = 2 const.GLV_STATE_DL_OK = 3 const.GLV_STATE = { A = 1, B = 2, C = 3} print(const.GLV_STATE.A) |
Likes: GregBUG, QuasarCreator, dealsnap, AhBadiane
Comments
however, I also use lua "constant" too
That's a perfect solution to hide all the little quirks that you often need when swapping from iOS to Android or iPhone to iPad.
It would be cool if the preprocessor could actually get built into Gideros studio!
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
nice, nice, nice !
thanks!
www.tntengine.com
sorry but it was not intentionally... really (i'm not a spammer)
but when i clicked over "Post Comment" button in my preceding post the site says me "String could not be parsed as xml" ??? and do a triple post! ?
and blocked me (as a spammer for 600 secs) (
a forum bug ?
@gorkem: please delete my triple post!
sorry. (
here is a screen...
www.tntengine.com
Since it uses AJAX to post, it probably sends info to server, and can't correctly parse server's xml response, but post is still posted to forum.
It was probably a server maintenance or something like that.
And don't delete your tripple post, or mine post won't make sense
Not sure about this forum issue. If you happen to bump into it more frequently, just let me know and I'll try to find a solution to it, by at least moving to a newer version (which I do not want in fact - "if it works, do not touch it")
Likes: ar2rsawseen
Maybe asking too much, do you have the solution apply this function for different tables?
I proved to adapt your code without success:
init.lua
I have this error
Thanks a lot
Did you put that function in init.lua before all the other code? (Or in a file you have set as a dependency of your main loading file?)
I can't really tell more without seeing the actual context you are using the code in, but my guess is you need to make sure the function is defined before the code you are calling it in--which is usually why you get the error you mentioned.
I would love to see an error list to, but most of the errors I have seen are LUA errors, and thus sort of generic themselves.
sorry, I renamed function,
your function was called "createConstantVariable(const)"
I didn't see it and named mine createConstTable, so if you have removed your function definition, you are still trying to call it somewhere in the code
Now work really well!!! >-