&p lpxserver˂E˂E ut-table.lua makeclass("unittests") function unittests.tables() -- check table.count assert(table.count({}) == 0) assert(table.count({a=1,b=2}) == 2) assert(table.count({[2]=5,[5]=3}) == 2) -- check table.clear local t = { a = 1, b = 2 } table.clear(t, true) assert(t.a == nil) assert(t.b == nil) assert(table.count(t) == 0) -- check table.empty assert(table.empty({}) == true) assert(table.empty({1}) == false) assert(table.empty({a=1}) == false) -- check table.equal assert(table.equal({},{})) assert(not table.equal({}, {1})) assert(not table.equal({1}, {})) assert(table.equal({1,2,3}, {1,2,3})) assert(not table.equal({1,2,3}, {1,5,3})) assert(not table.equal({1,2}, {1,2,3})) assert(not table.equal({1,2,3}, {1,2})) assert(table.equal({a=1,b=2},{a=1,b=2})) assert(not table.equal({a=1,b=3},{a=1,b=2})) -- check table.push t = {} table.push(t, 1) assert(table.equal(t, {1})) table.push(t, 2) assert(table.equal(t, {1,2})) table.push(t, 3) assert(table.equal(t, {1,2,3})) -- check table.findremove t = {1,2,3,4,5,1,2,3,4,5} table.findremove(t, 2) assert(table.equal(t, {1,3,4,5,1,3,4,5})) table.findremove(t, 5) assert(table.equal(t, {1,3,4,1,3,4})) table.findremove(t, 1) assert(table.equal(t, {3,4,3,4})) end function unittests.deque() local d = deque.create() for i=1,7 do for j=1,i do d:pushr(j) end for j=1,i do assert(d:nthl(j) == j) end for j=1,i do assert(d:popl() == j) end end for i=1,7 do for j=1,i do d:pushl(j) end for j=1,i do assert(d:nthr(j) == j) end for j=1,i do assert(d:popr() == j) end end for i=1,7 do for j=1,i do d:pushr(j) end for j=1,i do assert(d:popr() == i+1-j) end end end  rh`ut-globaldb.luammakeclass("unittests") function unittests.globaldb() local g1a = global.table("unittest-g1") local g2a = global.table("unittest-g2") local g1b = global.table("unittest-g1") local g2b = global.table("unittest-g2") assert(g1a == g1b) assert(g2a == g2b) assert(g1a.__global == "unittest-g1") assert(g2a.__global == "unittest-g2") end S/Rut-tablecmp.lua> -- the tdc function calculates diffs, and returns those -- diffs as a human-readable string. local tdc = table.diffcompare -- the tda function calculates diffs, applies the diffs to the second -- table, and then returns true if the second table equals the first. local tda = table.diffapply function unittests.diffcompare() local mtab = nil local rtab = nil -- No differences in these simple-valued tables. assert(tdc({}, {a=true}, {}, {a=true}) == "") assert(tdc({}, {a=5}, {}, {a=5}) == ""); assert(tdc({}, {a="foo"}, {}, {a="foo"}) == "") -- Test transmission of missing simple values. assert(tdc({}, {a=true}, {}, {}) == "a=true;") assert(tdc({}, {a=5}, {}, {}) == "a=5;"); assert(tdc({}, {a="foo"}, {}, {}) == "a=foo;") -- Test the replacement of simple values. assert(tdc({}, {a=true}, {}, {a=false}) == "a=true;") assert(tdc({}, {a=5}, {}, {a=4}) == "a=5;"); assert(tdc({}, {a="foo"}, {}, {a="bar"}) == "a=foo;") -- Test the clearing of values. assert(tdc({}, {}, {}, {a=true}) == "a=nil;") assert(tdc({}, {}, {}, {a=5}) == "a=nil;"); assert(tdc({}, {}, {}, {a="foo"}) == "a=nil;") -- Try boolean keys. assert(tdc({}, {[true]=3}, {}, {}) == "true=3;") assert(tdc({}, {}, {}, {[true]=3}) == "true=nil;") -- Try number keys. assert(tdc({}, {[7]=3}, {}, {}) == "7=3;") assert(tdc({}, {}, {}, {[7]=3}) == "7=nil;") -- Try a table with multiple keys. assert(tdc({}, {a=4, b=5, c=6}, {}, {b=5, c=7, d=8}) == "a=4;c=6;d=nil;") -- Nonsortable keys should be ignored (no diffs). assert(tdc({}, {[{}]=3}, {}, {}) == "") -- Try a table containing a class. assert(tdc({}, {a=deque}, {}, {}) == "a=class deque;") -- Try a table containing a pointer to the global environment. assert(tdc({}, {a=_G}, {}, {}) == "a=globals;") -- GlobalDB tables should be forced to NIL. assert(tdc({}, {a=global.table("foo")}, {}, {a=global.table("foo")}) == "a=nil;"); assert(tdc({}, {}, {}, {a=global.table("foo")}) == "a=nil;"); assert(tdc({}, {a=global.table("foo")}, {}, {}) == ""); -- Set up some numbered tables for tests involving such. local mtab10 = {} local stab10 = {} local mtnmap = {} local stnmap = {} mtnmap[mtab10] = 10 stnmap[stab10] = 10 -- confirm that numbered tables are being transmitted. assert(tdc(mtnmap, {a=mtab10}, stnmap, {}) == "a=table 10;") assert(tdc(mtnmap, {a=mtab10}, stnmap, {a=stab10}) == "") assert(tdc(mtnmap, {a=3}, stnmap, {a=stab10}) == "a=3;") assert(tdc(mtnmap, {}, stnmap, {a=stab10}) == "a=nil;") -- confirm that unnumbered tables are forced to nil. assert(tdc(mtnmap, {a={}}, stnmap, {}) == "") assert(tdc(mtnmap, {a={}}, stnmap, {a=3}) == "a=nil;") -- transmit a correction to the metatable. mtab={} stab={} setmetatable(mtab, mtab10) setmetatable(stab, stab10) assert(tdc(mtnmap, mtab, stnmap, {}) == "nil=table 10;") assert(tdc(mtnmap, mtab, stnmap, stab) == "") assert(tdc(mtnmap, {}, stnmap, stab) == "nil=nil;") -- we're not going to test tangibles -- creating tangibles here is too difficult. end function unittests.diffapply() local tab10={id=tab10} local tab11={id=tab11} local tnmap={} tnmap[tab10] = 10 tnmap[tab11] = 11 local mtab=nil local stab=nil -- verify some simple values. assert(tda(tnmap, {a=1}, {})) assert(tda(tnmap, {[true]="foo"}, {})) assert(tda(tnmap, {[3]=false}, {})) -- verify a table with multiple simple values. assert(tda(tnmap, {a=1, b=2, c=3}, {})) -- verify that it can remove or replace wrong values. assert(tda(tnmap, {a=1,b=2}, {b=3,c=4})) -- verify a table containing another table. assert(tda(tnmap, {a=tab10, b=tab11}, {})) -- verify a table containing a class. assert(tda(tnmap, {a=deque, b=table}, {})) -- verify a table containing the global environment. assert(tda(tnmap, {a=_G}, {})) -- GlobalDB tables should be forced to NIL. rtab={a=3} assert(not tda({}, {a=global.table("foo")}, rtab)) assert(rtab.a == nil) -- Unnumbered tables should be forced to NIL. rtab={a=3} assert(not tda({}, {a={}}, rtab)) assert(rtab.a == nil) -- transmit a correction to the metatable mtab={} rtab={} setmetatable(mtab, tab10) assert(tda(tnmap, mtab, rtab)) assert(getmetatable(rtab) == tab10) -- transmit a clearing of the metatable mtab={} rtab={} setmetatable(rtab, tab10) assert(tda(tnmap, mtab, rtab)) assert(getmetatable(rtab) == nil) -- don't test tangibles. end Wq login.luamakeclass('login') function login.interface(actor, place) gui.menu_item("cb_becomeplayer", "Become a Player") gui.menu_item("cb_p123", "Print 1, 2, 3") end function login.cb_becomeplayer(actor, place, dialog) tangible.setclass(actor, player) tangible.animate(actor,{action="warp",plane="main",x=0,y=0,z=0}) end function login.cb_p123(actor, place, dialog) print(1) wait(1) print(2) wait(1) print(3) end -- this is function documentation for setfoo. function setfoo(n) tangible.nopredict() tangible.actor().inventory.foo = n end function buildq() return tangible.build{class="login", x=10, y=0, z=0, plane="nowhere", graphic="what"} end nGc horps.luaD makeclass('player') -- -- Data Structure -- Army.Count -- Army.Kind 'r','p','s' -- function player.interface(actor, place) gui.menu_item("cb_north", "Go North") gui.menu_item("cb_south", "Go South") gui.menu_item("cb_east", "Go East") gui.menu_item("cb_west", "Go West") gui.menu_item("cb_map", "Show the Map") gui.menu_item("cb_emit_army","Emit an Army") gui.menu_item("cb_emit_buff","Emit a Buff") end function player:printanimstate() local graphic,plane,x,y,z,facing = tangible.animstate(self) print("Resulting state: ", graphic, plane, x, y, z, facing) end function player.cb_north(actor, place, dialog) tangible.animate(place, {action="walk", dy=1}) actor:printanimstate() end function player.cb_south(actor, place, dialog) tangible.animate(place, {action="walk", dy=-1}) actor:printanimstate() end function player.cb_east(actor, place, dialog) tangible.animate(place, {action="walk", dx=1}) actor:printanimstate() end function player.cb_west(actor, place, dialog) tangible.animate(place, {action="walk", dx=-1}) actor:printanimstate() end function player.cb_emit_army(actor,place,dialog) local _,pl,ax,ay=tangible.animstate(actor) t={class='army',x=ax,y=ay,z=0,plane=pl,graphic='army'} pprint("building ",t) tangible.build(t) t.kind='r' t.count=5 end function player.cb_emit_buff(actor,place,dialog) local _,pl,ax,ay=tangible.animstate(actor) t={class='army',x=ax,y=ay,z=0,plane=pl,graphic='buff'} pprint("building ",t) tangible.build(t) end makeclass('army') makeclass('buff') function seq(a,b,c) return a<=b and b<=c or false end function player.cb_map(actor,place,dialog) local rad=2 local scratch={} local lis=tangible.near(actor,rad,true,false) pprint("cb_map ",lis) for _,t in pairs(lis) do local graphic,plane,x,y,z,facing = tangible.animstate(t) local c=tangible.getclass(t) local dx,dy=tangible.xyz(t) local offset=(dy+rad)*(rad*2+1)+dx+rad local cl=tangible.getclass(t) print("Offset of "..cl.." is "..offset) if not scratch[offset] then scratch[offset]={} end if not scratch[offset].armies then scratch[offset].armies={} end if cl=='player' then table.insert(scratch[offset].armies,t) end if not scratch[offset].count then scratch[offset].count={} if not scratch[offset].count[cl] then scratch[offset].count[cl]=0 end if t.count then scratch[offset].count[cl]=scratch[offset].count[cl]+t.count end end for dy=-rad,rad do for line=0,1 do local lbuf="" for dx=-rad,rad do if line==0 then lbuf=lbuf.."---" elseif line==1 then local kc=0 local tc=0 local kstr=' ' for k,c in pairs(scratch[offset].count) do if c>0 then kc=kc+1 tc=tc+c if kc>1 then kstr='M' else kstr=k end end end lbuf=lbuf.."-"..kstr..(tc>0 and tc or " ") end end lbuf=lbuf.."-" print(lbuf) end end lbuf="" for dx=-rad,rad do lbuf=lbuf.."---" end lbuf=lbuf.."-" print(lbuf) end end /3_G lpxserverU$ =ģU/ U}VE?U:w% U\w?Uq U _?U1hZUu U^w?U f8)Ui Uˍ?URU Ut U6a2?U]0 U?U \AQ:aZmE \AQ hh?=x