moonscript/tests/outputs/class.lua

165 lines
3.6 KiB
Lua
Raw Normal View History

local Hello
Hello = (function(_parent_0)
2011-07-14 07:02:07 +00:00
local _base_0 = {
hello = function(self)
return print(self.test, self.world)
end,
__tostring = function(self)
return "hello world"
end
}
2011-06-15 15:52:01 +00:00
_base_0.__index = _base_0
2011-07-14 07:02:07 +00:00
if _parent_0 then
setmetatable(_base_0, getmetatable(_parent_0).__index)
end
local _class_0 = setmetatable({
__init = function(self, test, world)
2011-06-15 15:52:01 +00:00
self.test, self.world = test, world
return print("creating object..")
2011-07-14 07:02:07 +00:00
end
}, {
__index = _base_0,
__call = function(mt, ...)
2011-06-15 15:52:01 +00:00
local self = setmetatable({}, _base_0)
mt.__init(self, ...)
return self
2011-07-14 07:02:07 +00:00
end
})
2011-07-04 18:36:26 +00:00
_base_0.__class = _class_0
return _class_0
2011-06-15 15:52:01 +00:00
end)()
2011-06-15 06:13:33 +00:00
local x = Hello(1, 2)
x:hello()
2011-06-16 05:41:17 +00:00
print(x)
local Simple
Simple = (function(_parent_0)
2011-07-14 07:02:07 +00:00
local _base_0 = {
cool = function(self)
return print("cool")
end
}
2011-06-16 05:41:17 +00:00
_base_0.__index = _base_0
2011-07-14 07:02:07 +00:00
if _parent_0 then
setmetatable(_base_0, getmetatable(_parent_0).__index)
end
local _class_0 = setmetatable({
__init = function(self, ...)
if _parent_0 then
return _parent_0.__init(self, ...)
end
2011-07-14 07:02:07 +00:00
end
}, {
__index = _base_0,
__call = function(mt, ...)
2011-06-16 05:41:17 +00:00
local self = setmetatable({}, _base_0)
mt.__init(self, ...)
return self
2011-07-14 07:02:07 +00:00
end
})
2011-07-04 18:36:26 +00:00
_base_0.__class = _class_0
return _class_0
2011-06-16 05:41:17 +00:00
end)()
local Yikes
Yikes = (function(_parent_0)
2011-07-14 07:02:07 +00:00
local _base_0 = { }
2011-06-16 05:41:17 +00:00
_base_0.__index = _base_0
if _parent_0 then
setmetatable(_base_0, getmetatable(_parent_0).__index)
end
2011-07-14 07:02:07 +00:00
local _class_0 = setmetatable({
__init = function(self)
return print("created hello")
end
}, {
__index = _base_0,
__call = function(mt, ...)
2011-06-16 05:41:17 +00:00
local self = setmetatable({}, _base_0)
mt.__init(self, ...)
return self
2011-07-14 07:02:07 +00:00
end
})
2011-07-04 18:36:26 +00:00
_base_0.__class = _class_0
return _class_0
2011-06-16 05:41:17 +00:00
end)(Simple)
x = Yikes()
x:cool()
local Hi
Hi = (function(_parent_0)
2011-07-14 07:02:07 +00:00
local _base_0 = {
cool = function(self, num)
return print("num", num)
end
}
_base_0.__index = _base_0
2011-07-14 07:02:07 +00:00
if _parent_0 then
setmetatable(_base_0, getmetatable(_parent_0).__index)
end
local _class_0 = setmetatable({
__init = function(self, arg)
return print("init arg", arg)
end
}, {
__index = _base_0,
__call = function(mt, ...)
local self = setmetatable({}, _base_0)
mt.__init(self, ...)
return self
2011-07-14 07:02:07 +00:00
end
})
2011-07-04 18:36:26 +00:00
_base_0.__class = _class_0
return _class_0
end)()
Simple = (function(_parent_0)
2011-07-14 07:02:07 +00:00
local _base_0 = {
cool = function(self)
return _parent_0.cool(self, 120302)
end
}
_base_0.__index = _base_0
if _parent_0 then
setmetatable(_base_0, getmetatable(_parent_0).__index)
end
2011-07-14 07:02:07 +00:00
local _class_0 = setmetatable({
__init = function(self)
return _parent_0.__init(self, "man")
end
}, {
__index = _base_0,
__call = function(mt, ...)
local self = setmetatable({}, _base_0)
mt.__init(self, ...)
return self
2011-07-14 07:02:07 +00:00
end
})
2011-07-04 18:36:26 +00:00
_base_0.__class = _class_0
return _class_0
end)(Hi)
x = Simple()
2011-07-04 18:36:26 +00:00
x:cool()
print(x.__class == Simple)
local Okay
Okay = (function(_parent_0)
local _base_0 = {
something = 20323
}
_base_0.__index = _base_0
if _parent_0 then
setmetatable(_base_0, getmetatable(_parent_0).__index)
end
local _class_0 = setmetatable({
__init = function(self, ...)
if _parent_0 then
return _parent_0.__init(self, ...)
end
end
}, {
__index = _base_0,
__call = function(mt, ...)
local self = setmetatable({}, _base_0)
mt.__init(self, ...)
return self
end
})
_base_0.__class = _class_0
return _class_0
end)()