1

Topic: We study Lua together - how to set constants?

Hello! Continuing a series of mine  questions on integration Lua into a C ++ application (I hope, what my posts still help someone) I want to ask - and it is possible generally in Lua to set constants? I learned to set global variables, but they can be redefined from a script, including as it appeared, it is possible to redefine and library constants: math.pi = 2 message ("The Pi:". math.pi) deduces: The Pi: 2 Looks, as full  in design of language

2

Re: We study Lua together - how to set constants?

Hello, Marty, you wrote: M> Looks, as full  in design of language of speaker. Rarely where in dynamics you will meet constants. It is possible to bypass through read only table

3

Re: We study Lua together - how to set constants?

Hello, Marty, you wrote: M> Looks, as full  in design of language in a case  and other similar things on it it is possible to tell only "and you so do not do".

4

Re: We study Lua together - how to set constants?

Hello, Marty, you wrote: M> Hello! M> continuing a series of mine  questions on integration Lua into a C ++ application (I hope, what my posts still help someone) I want to ask - and it is possible generally in Lua to set constants? M> I learned to set global variables, but they can be redefined from a script, including as it appeared, it is possible to redefine and library constants: M> math.pi = 2 M> message ("The Pi:". math.pi) M> M> deduces: M> The Pi: 2 M> Looks, as full  in design of language It not the bug is a feature function const (x) return setmetatable ({}, {__ index=x, __ newindex=function (t, k, v) error "read only" end}) end m=const {pi=3.14, e=2.71} print (m.pi, m.e) m.pi=2 print (m.pi, m.e)

5

Re: We study Lua together - how to set constants?

Hello, Marty, you wrote: M> Looks, as full  in design of language 1) use the squirrel and-or 2)   (at the same time it is possible to throw out the debug code)

6

Re: We study Lua together - how to set constants?

Hello, kov_serg, you wrote: _> It not the bug is a feature _> _> function const (x) _> return setmetatable ({}, {__ index=x, __ newindex=function (t, k, v) error "read only" end}) _> end _> m=const {pi=3.14, e=2.71} _> print (m.pi, m.e) _> m.pi=2 _> print (m.pi, m.e) _> I in Lua not , what does this code? At me "read only" deduces

7

Re: We study Lua together - how to set constants?

Hello, IID, you wrote: M>> Looks, how full  in design of language IID> 1) use the squirrel That? IID> and-or IID> 2)   (at the same time it is possible to throw out the debug code) did not understand idea

8

Re: We study Lua together - how to set constants?

Hello, Marty, you wrote: IID>> 1) use squirrel M> That? Squirrel. IID>> and-or IID>> 2)   (at the same time it is possible to throw out the debug code) M> did not understand idea #define MY_SUPER_CONST 1488... return function (x) cache [MY_SUPER_CONST] = x end

9

Re: We study Lua together - how to set constants?

Hello, Marty, you wrote: IID>> 1) use squirrel M> That? The squirrel it http://squirrel-lang.org/ by the way, I join the council, a suitable thing.