Posted 15 March 2013 - 10:55 AM
I'm working on a way to create objects in lua using functions with their own enviroment. (That should mean I create a function that represents my object) It all works great, I can create objects and they are all separate of each other, but I haven't figured out how to extend an object using anotherone.
What I did is I've set a function enviroment and simply added the functions from the other object into it. Unfortiounatly, they do show up if I use getfenv, but they are still bound to their old fenv. That means if I extend a with b and b has the function b.func I can now access it typing a.func, but if a has (native) functions like a.foo I can't access them from a.func
For instance:
a.foo = function() end
b.func = function() foo() end
a.func()
-> error because foo is nil
Is there a way to solve that?
What I did is I've set a function enviroment and simply added the functions from the other object into it. Unfortiounatly, they do show up if I use getfenv, but they are still bound to their old fenv. That means if I extend a with b and b has the function b.func I can now access it typing a.func, but if a has (native) functions like a.foo I can't access them from a.func
For instance:
a.foo = function() end
b.func = function() foo() end
a.func()
-> error because foo is nil
Is there a way to solve that?