mirror of
https://github.com/CPunch/Cosmo.git
synced 2025-11-14 03:20:04 +00:00
added IStrings, added __index functionality
This commit is contained in:
@@ -1,26 +1,14 @@
|
||||
class test
|
||||
function __init(self, str)
|
||||
self.hello = str
|
||||
end
|
||||
-- crafts a dummy class
|
||||
class test end
|
||||
|
||||
function print(self, i)
|
||||
var str = self.hello
|
||||
-- instance of test
|
||||
var obj = test()
|
||||
|
||||
for (var x = i; x > 0; x=x-1) do
|
||||
str = str .. "!"
|
||||
end
|
||||
|
||||
print(str)
|
||||
test.__index = function(self, key)
|
||||
print("__index called!")
|
||||
if (key == "lol") then
|
||||
return 9001
|
||||
end
|
||||
end
|
||||
|
||||
var obj = test("Hello world")
|
||||
for (var i = 1; i <= 1; i=i+1) do
|
||||
obj.print(i)
|
||||
end
|
||||
|
||||
test.debug = function(self)
|
||||
print("hi from " .. self)
|
||||
end
|
||||
|
||||
obj.debug()
|
||||
print(obj["lol"]) -- should print 9001?
|
||||
Reference in New Issue
Block a user