rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 17 Jun 2015 05:59 PM |
ok i have my nooby wrapper here:
function Wrap(object, tab, lock) local new = setmetatable(tab, {__index = object}) local proxy = newproxy(true) local mt = getmetatable(proxy) mt.__index = new mt.__newindex = function(t,i,v) if new[i] then new[i] = v else error(v.." is not a valid member of "..i) end end if lock then mt.__metatable = "Locked, noobs" end return proxy end
it works and all, but i cannot use roblox created methods like :WaitForChild() or something how kan i do it |
|
|
| Report Abuse |
|
|
| |
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
| |
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
| |
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
| |
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
| |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Jun 2015 07:00 PM |
| tracking this cuz i need to know this 2 |
|
|
| Report Abuse |
|
|
|
| 17 Jun 2015 07:01 PM |
Actually... you are doing it wrong. You index through the userdata created. It should fizzle.
local Object = {}
Object.new = function() local this = {}
local proxy = newproxy(true) local proxy_meta = getmetatable(proxy)
proxy_meta.__index = this proxy_meta.__newindex = function(self, i, v) --TODO: Checked if allowed to set or whatever end
return proxy end
return Object |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 17 Jun 2015 07:04 PM |
it works for me
the userdata is relaying the request to the table i want to add, which'll hold all the extra stuff i add to my wrapper if the table doesn't contain it, then it'll relay it to the original object to see if it has that thing
|
|
|
| Report Abuse |
|
|
|
| 17 Jun 2015 07:30 PM |
You misunderstand the concept of userdata.
Since this is Lua 5.1, the reason we use userdata like this is to filter what the table contains and how it is interacted with.
Call really shouldn't be on an array or a metatable... it should be an objects methods Add really shouldn't be on an array or a metatable... it should be an two objects
Since we have a filter letting you decide what can happen, it is easier for error() checking, locking variables to prevent errors, setting a normalization of units, and more.... since everything fizzles to the __index and __newindex...
Metatable allows you to set certain methods to happen in the environment, not store data.
http://www.lua.org/pil/28.1.html
Gives a good example of using programming with Lua and not plain Lua. It has more versatility through programming, naturally.
|
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 17 Jun 2015 07:32 PM |
ok tl;dr but it works so im good |
|
|
| Report Abuse |
|
|
|
| 17 Jun 2015 07:34 PM |
| You've lost all respect for me and now I will never help again. |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 17 Jun 2015 07:37 PM |
I think you mean, "I've lost all respect for you" pls i sory |
|
|
| Report Abuse |
|
|
|
| 17 Jun 2015 07:38 PM |
| You've lost all respect from me and now I will never help again.* |
|
|
| Report Abuse |
|
|