Posted 06 March 2013 - 01:18 AM
Hey, i am having some problems. I "followed" this tutorial : http://www.computercraft.info/forums2/index.php?/topic/10570-functional-oop-in-lua/
I made the following "class":
There is an error at the "print" line. It says "attempt to call nil", and after some researching, i found out, that the function print is not known inside the class. But why?
Here my "new" function:
I call it like this:
Sorry for my bad english, i hope you can help me ;)/>
I made the following "class":
function Vector2(x,y)
X = x
Y = y
print("hi")
end
I put a print in there because i wanted to know when the "constructor" is called.There is an error at the "print" line. It says "attempt to call nil", and after some researching, i found out, that the function print is not known inside the class. But why?
Here my "new" function:
function new(Class, ...)
local Table = {}
setfenv(Class, Table)
Class(...)
return Table
end
I call it like this:
import(vector2) -- because the Vector2 class is in a seperated file
myvector = new(Vector2, 4, 9)
Sorry for my bad english, i hope you can help me ;)/>