Would be appreciated
Forum
CS2D Scripts What are rawset, rawget?What are rawset, rawget?
1 reply 1
Would be appreciated
This code demonstrate it pretty well
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
-- rawget demonstration local t = setmetatable({value = 123}, {__index = string}) print(t.value) -- 123 print(rawget(t, "value")) -- 123 print(t.sub) -- function: string.sub print(rawget(t, "sub")) -- nil -- rawset demonstration t = setmetatable(t, {__newindex = function(self, key, value) 	print("Setting \""..key.."\" to \""..tostring(value).."\"") 	rawset(self, key, value) -- Note that we use "rawset" here to actually set the value and to prevent recursion. end}) t.hello = "World" -- Setting "hello" to "World" rawset(t, "sub", 456) -- nothing printed print(t.hello) -- World print(t.sub) -- 456
1