|
| 05 Jun 2016 11:02 AM |
Alright, i got this.
local Point=newproxy(true) do getmetatable(Point).__index={new=function(p0,p,i) p0=p0 or Vector2.new() p=p or Vector2.new() newPoint=newproxy(true) getmetatable(newPoint).__index={ p0=p0, p=p, i=i, } getmetatable(newPoint).__newindex=function(self,i,v) return rawset(self,key,value) end getmetatable(newPoint).__tostring=function() return newPoint.p0..","..newPoint.p..","..newPoint.i end getmetatable(newPoint).__metatable="This metatable is locked." return newPoint end} end
local a=Point.new(Vector2.new(),Vector2.new(),1) a.p=Vector2.new(10,0)
Actually, i got an error when trying to set the a.p value. Could someone help me? |
|
|
| Report Abuse |
|
|
| |
|
|
| 05 Jun 2016 11:09 AM |
what is code suppose to do ?
https://gist.github.com/Rapptz/11305872 |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2016 11:10 AM |
p0,p,andi are in the __index table, in __newindex you're trying to change the one in the regular but you can't do that because it's a userdata.
local tbl = {p0=p0,p=p,i=i} getmetatable(newPoint).__index=tbl getmetatable(newPoint).__newindex=function(self,i,v) tbl[i] = v end |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2016 11:12 AM |
| he is right but what is this code.. |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2016 11:13 AM |
Really @Flux_Capacitor? I'm calling "A" as a Point.new(), couldn't i do A.p=Vector2.new(1,1)? What should i do then?
|
|
|
| Report Abuse |
|
|
|
| 05 Jun 2016 11:14 AM |
It's a module script. I'm requiring it from another one and then declaring 'local a'. |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2016 11:19 AM |
| I already gave you the solution to fix it |
|
|
| Report Abuse |
|
|