diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2024-05-27 00:11:26 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2024-05-27 00:11:26 -0300 |
commit | e62ec5ac36188cb12411a8c720daebce77ecf645 (patch) | |
tree | b1a2ce8e95ffc6e92ee31c1e271b0fcafe8a0b2f /tests.cratera | |
parent | 9dea1c26b487ae723d99ba1e5e5887b09aec87dd (diff) |
Set up a "build system"
Diffstat (limited to 'tests.cratera')
-rw-r--r-- | tests.cratera | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/tests.cratera b/tests.cratera deleted file mode 100644 index fd97917..0000000 --- a/tests.cratera +++ /dev/null @@ -1,86 +0,0 @@ --- Cratera-specific tests. Run Lua test suite separately. - -local t = setmetatable({}, { __tostring=function()return"t"end}) -local F = {} -local T = {} -t.t = t -t.tt = t -t[T] = t -t.f = print -t.ff = print -t.g = function(self, a) print(self, a[1]) end -t[F] = print -local _f="f" -local _t="t" - --- print("------ t:[k]()") --- t:f(1) -- plain old lua --- t:[_f](2) -- simple string key in register --- t:[string.char(string.byte("f"))](3,32,33) -- string key from function --- t:["f".."f"](4) -- string key from concatenation --- t:["f"..string.sub("afun",2,2)](5,52,53) -- concatenation with function result --- t:[(string.sub("afun",2,2))](6,62,63) -- function result in parentheses --- t:[(function()return"f"end)()](7) -- closure in key --- -- be careful with the ambiguous function call!!! --- ;(function()return t end)():[(function()return"f"end)()](8) -- closure in object and in key --- t:[F](9) -- object key - --- standard lua tests (compiler/passthrough) -do - print("------ standard lua tests (compiler/passthrough)") - local x - t["t"]:f(1) -end - -print("------ t:[k].f()") -t:t.f(1) -- string identifier -t:[_t].f(2) -- string key in register -t:[string.char(string.byte("t"))].f(3,32,33) -- string key from function -t:["t".."t"].f(4) -- string key from concatenation -t:["t"..string.sub("atable",2,2)].f(5,52,53) -- concatenation with function result -t:[(string.sub("atable",2,2))].f(6,62,63) -- function result in parentheses -t:[(function()return"t"end)()].f(7) -- closure in key -do end(function()return t end)():[(function()return"t"end)()].f(8) -- closure in object and in key, with "end" keyword at the start --- be careful with the ambiguous function call!!! -;(function()return t end)():[(function()return"t"end)()].f(9) -- closure in object and in key, with semicolon at the start -t:[T].f(10) -- object key -_=(t:[_t].f(11)) -- inside () - -t:[_t].g {12} -- table call -t:[_t].f "13" -- string call - - -entity = {} - -inventory = {get=false, set=false, size=false} -inventory.new=function(size) - local t = {size=function() return size end} - function t.set(e, i, o) - if i <= 0 or i > e:[inventory].size() then error() end - e[inventory][i] = o - end - function t.get(e, i) - if i <= 0 or i > e:[inventory].size() then error() end - return e[inventory][i] - end - return t -end -inventory.of=function(e) -- helper for passing standalone inventories around - return {get=function(...)return e:[inventory].get(...)end, set=function(...)return e:[inventory].set(...)end, size=function(...)return e:[inventory].size(...)end} -end - -entity[inventory] = inventory.new(5) - -entity:[inventory].set(1, "Hello World!") - -print(entity:[inventory].get(1)) - -for i=1, entity:[inventory].size() do - print(i, entity:[inventory].get(i)) -end - -local myinv = inventory.of(entity) - -for i=1, myinv.size() do - print("wrapped", i, myinv.get(i)) -end |