diff options
-rw-r--r-- | engines/sword25/util/pluto/Makefile | 29 | ||||
-rw-r--r-- | engines/sword25/util/pluto/pptest.cpp | 95 | ||||
-rw-r--r-- | engines/sword25/util/pluto/pptest.lua | 168 | ||||
-rw-r--r-- | engines/sword25/util/pluto/puptest.cpp | 81 | ||||
-rw-r--r-- | engines/sword25/util/pluto/puptest.lua | 93 |
5 files changed, 0 insertions, 466 deletions
diff --git a/engines/sword25/util/pluto/Makefile b/engines/sword25/util/pluto/Makefile deleted file mode 100644 index 611ecc83d2..0000000000 --- a/engines/sword25/util/pluto/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -LDLIBS= -lm -ldl -llua -LDFLAGS = -rdynamic # -L../lua-5.1.3/src -# CFLAGS= -g3 -Wall -fprofile-arcs -ftest-coverage -CFLAGS= -g3 -Wall -ansi -pedantic - -LIBTOOL=libtool --tag=CC - -default: pluto.so pptest puptest - -%.lo: %.c - $(LIBTOOL) --mode=compile cc $(CFLAGS) -c $< - -pluto.so: pluto.lo pdep.lo lzio.lo - $(LIBTOOL) --mode=link cc -rpath /usr/local/lib/lua/5.1 -o libpluto.la $^ - mv .libs/libpluto.so.0.0.0 $@ - -test: pptest puptest pptest.lua puptest.lua pluto.so - ./pptest - ./puptest - -pptest: pptest.o - $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) - -puptest: puptest.o - $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) - -clean: - -rm -r *.so *.la *.lo .libs *.a *.o *.bb *.bbg *.da *.gcov pptest puptest test.plh - diff --git a/engines/sword25/util/pluto/pptest.cpp b/engines/sword25/util/pluto/pptest.cpp deleted file mode 100644 index 1bfecf2b75..0000000000 --- a/engines/sword25/util/pluto/pptest.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* $Id$ */ - -#include <stdio.h> -#include <stdlib.h> - -#include "lua.h" -#include "lualib.h" -#include "lauxlib.h" - -static int LUAF_createludata(lua_State *L) -{ - lua_pushlightuserdata(L, (void*)321); - return 1; -} - -/* A userdata that may be literally persisted */ -static int LUAF_boxinteger(lua_State *L) -{ - /* num */ - int* ptr = lua_newuserdata(L, sizeof(int)); - /* num udata */ - *ptr = luaL_checkint(L, 1); - lua_newtable(L); - /* num udata mt */ - lua_pushstring(L, "__persist"); - /* num udata mt "__persist" */ - lua_pushboolean(L, 1); - /* num udata mt "__persist" true */ - lua_rawset(L, 3); - /* num udata mt */ - lua_setmetatable(L, 2); - /* num udata */ - return 1; -} - -static int LUAF_boxboolean(lua_State *L) -{ - /* bool */ - char* ptr = lua_newuserdata(L, sizeof(char)); - /* bool udata */ - *ptr = lua_toboolean(L, 1); - lua_newtable(L); - /* num udata mt */ - lua_pushstring(L, "__persist"); - /* num udata mt "__persist" */ - lua_getglobal(L, "booleanpersist"); - /* num udata mt "__persist" booleanpersist */ - lua_rawset(L, 3); - /* num udata mt */ - lua_setmetatable(L, 2); - /* num udata */ - return 1; -} - -static int LUAF_unboxboolean(lua_State *L) -{ - /* udata */ - lua_pushboolean(L, *(char*)lua_touserdata(L, 1)); - /* udata bool */ - return 1; -} - -static int LUAF_onerror(lua_State *L) -{ - - const char* str = 0; - if(lua_gettop(L) != 0) - { - str = lua_tostring(L, -1); - printf("%s\n",str); - } - return 0; -} - -int main() -{ - lua_State* L = lua_open(); - - luaL_openlibs(L); - lua_settop(L, 0); - - lua_register(L, "createludata", LUAF_createludata); - lua_register(L, "boxinteger", LUAF_boxinteger); - lua_register(L, "boxboolean", LUAF_boxboolean); - lua_register(L, "unboxboolean", LUAF_unboxboolean); - lua_register(L, "onerror", LUAF_onerror); - - lua_pushcfunction(L, LUAF_onerror); - luaL_loadfile(L, "pptest.lua"); - lua_pcall(L,0,0,1); - - lua_close(L); - - return 0; -} diff --git a/engines/sword25/util/pluto/pptest.lua b/engines/sword25/util/pluto/pptest.lua deleted file mode 100644 index 144da3ee80..0000000000 --- a/engines/sword25/util/pluto/pptest.lua +++ /dev/null @@ -1,168 +0,0 @@ --- $Id$ - -require "pluto" - -permtable = { 1234 } - -perms = { [coroutine.yield] = 1, [permtable] = 2 } - -twithmt = {} -setmetatable( twithmt, { __call = function() return 21 end } ) - -function testfenv() - return abc -end - -setfenv(testfenv, { abc = 456 }) - -function fa(i) - local ia = i + 1 - return fb(ia) -end - -function fb(i) - local ib = i + 1 - ib = ib + fc(ib) - return ib -end - -function fc(i) - local ic = i + 1 - coroutine.yield() - return ic*2 -end - -function func() - return 4 -end - -thr = coroutine.create(fa) -coroutine.resume(thr, 2) - -testtbl = { a = 2, [2] = 4 } - -function funcreturningclosure(n) - return function() - return n - end -end - -function nestedfunc(n) - return (function(m) return m+2 end)(n+3) -end - -testloopa = {} -testloopb = { testloopa = testloopa } -testloopa.testloopb = testloopb - -sharedref = {} -refa = {sharedref = sharedref} -refb = {sharedref = sharedref} - -sptable = { a = 3 } - -setmetatable(sptable, { - __persist = function(tbl) - local a = tbl.a - return function() - return { a = a+3 } - end - end -}) - -literaludata = boxinteger(71) - -function booleanpersist(udata) - local b = unboxboolean(udata) - return function() - return boxboolean(b) - end -end - -function makecounter() - local a = 0 - return { - inc = function() a = a + 1 end, - cur = function() return a end - } -end - -function uvinthreadfunc() - local a = 1 - local b = function() - a = a+1 - coroutine.yield() - a = a+1 - end - a = a+1 - b() - a = a+1 - return a -end - -uvinthread = coroutine.create(uvinthreadfunc) -coroutine.resume(uvinthread) - -niinmt = { a = 3 } -setmetatable(niinmt, {__newindex = function(key, val) end }) - - - - -local function GenerateObjects() - local Table = {} - - function Table:Func() - return { Table, self } - end - - function uvcycle() - return Table:Func() - end -end - -GenerateObjects() - - - -function debuginfo(foo) - foo = foo + foo - return debug.getlocal(1,1) -end - -rootobj = { - testfalse = false, - testtrue = true, - testseven = 7, - testfoobar = "foobar", - testfuncreturnsfour = func, - testnil = nil, - testthread = thr, - testperm = permtable, - testmt = twithmt, - testtbl = testtbl, - testfenv = testfenv, - testclosure = funcreturningclosure(11), - testnilclosure = funcreturningclosure(nil), - testnest = nestedfunc, - testludata = createludata(), - testlooptable = testloopa, - testsharedrefa = refa, - testsharedrefb = refb, - testsptable = sptable, - testliteraludata = literaludata, - testspudata1 = boxboolean(true), - testspudata2 = boxboolean(false), - testsharedupval = makecounter(), - testuvinthread = uvinthread, - testniinmt = niinmt, - testuvcycle = uvcycle, - testdebuginfo = debuginfo -} - -buf = pluto.persist(perms, rootobj) - -onerror() -outfile = io.open("test.plh", "wb") -outfile:write(buf) -outfile:close() diff --git a/engines/sword25/util/pluto/puptest.cpp b/engines/sword25/util/pluto/puptest.cpp deleted file mode 100644 index e9aa7ea305..0000000000 --- a/engines/sword25/util/pluto/puptest.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* $Id$ */ - -#include <stdio.h> -#include <stdlib.h> - -#include "lua.h" -#include "lualib.h" -#include "lauxlib.h" - -static int LUAF_checkludata(lua_State *L) -{ - lua_pushboolean(L, lua_touserdata(L, -1) == (void*)321); - return 1; -} - -static int LUAF_unboxinteger(lua_State *L) -{ - lua_pushnumber(L, *((int*)lua_touserdata(L, -1))); - return 1; -} - -static int LUAF_unboxboolean(lua_State *L) -{ - /* udata */ - lua_pushboolean(L, *(char*)lua_touserdata(L, 1)); - /* udata bool */ - return 1; -} - -static int LUAF_boxboolean(lua_State *L) -{ - /* bool */ - char* ptr = lua_newuserdata(L, sizeof(char)); - /* bool udata */ - *ptr = lua_toboolean(L, 1); - lua_newtable(L); - /* num udata mt */ - lua_pushstring(L, "__persist"); - /* num udata mt "__persist" */ - lua_getglobal(L, "booleanpersist"); - /* num udata mt "__persist" booleanpersist */ - lua_rawset(L, 3); - /* num udata mt */ - lua_setmetatable(L, 2); - /* num udata */ - return 1; -} - -static int LUAF_onerror(lua_State *L) -{ - - const char* str = 0; - if(lua_gettop(L) != 0) - { - str = lua_tostring(L, -1); - printf("%s\n",str); - } - return 0; -} - -int main() -{ - lua_State* L = lua_open(); - - luaL_openlibs(L); - lua_settop(L, 0); - - lua_register(L, "checkludata", LUAF_checkludata); - lua_register(L, "unboxinteger", LUAF_unboxinteger); - lua_register(L, "boxboolean", LUAF_boxboolean); - lua_register(L, "unboxboolean", LUAF_unboxboolean); - lua_register(L, "onerror", LUAF_onerror); - - lua_pushcfunction(L, LUAF_onerror); - luaL_loadfile(L, "puptest.lua"); - lua_pcall(L,0,0,1); - - lua_close(L); - - return 0; -} diff --git a/engines/sword25/util/pluto/puptest.lua b/engines/sword25/util/pluto/puptest.lua deleted file mode 100644 index e5ccdd64bd..0000000000 --- a/engines/sword25/util/pluto/puptest.lua +++ /dev/null @@ -1,93 +0,0 @@ --- $Id$ - -require "pluto" - -permtable = { 1234 } - -perms = { [1] = coroutine.yield, [2] = permtable } - -function testcounter(counter) - local a = counter.cur() - counter.inc() - return counter.cur() == a+1 -end - -function testuvinthread(func) - local success, result = coroutine.resume(func) - return success and result == 5 -end - - -function test(rootobj) - local passed = 0 - local total = 0 - local dotest = function(name,cond) - total = total+1 - if cond then - print(name, " PASSED") - passed = passed + 1 - else - print(name, "* FAILED") - end - end - - - dotest("Boolean FALSE ", rootobj.testfalse == false) - dotest("Boolean TRUE ", rootobj.testtrue == true) - dotest("Number 7 ", rootobj.testseven == 7) - dotest("String 'foobar' ", rootobj.testfoobar == "foobar") - dotest("Func returning 4 ", rootobj.testfuncreturnsfour() == 4) - dotest("Nil value ", rootobj.testnil == nil) - dotest("Thread resume ", coroutine.resume(rootobj.testthread) == true,14) - dotest("Table ", rootobj.testtbl.a == 2 and rootobj.testtbl[2] == 4); - dotest("Permanent table ", rootobj.testperm == permtable) - dotest("Table metatable ", rootobj.testmt() == 21) - dotest("Function env ", rootobj.testfenv() == 456) - dotest("Lua closure ", rootobj.testclosure() == 11) - dotest("Nil in closure ", rootobj.testnilclosure() == nil) - dotest("Nested func ", rootobj.testnest(1) == 6) - dotest("Light userdata ", checkludata(rootobj.testludata)) - dotest("Looped tables ", - rootobj.testlooptable.testloopb.testloopa == - rootobj.testlooptable) - dotest("Shared reference ", rootobj.testsharedrefa.sharedref == - rootobj.testsharedrefb.sharedref) - dotest("Identical tables ", rootobj.testsharedrefa ~= - rootobj.testsharedrefb) - dotest("Table special persist", rootobj.testsptable.a == 6) - dotest("Udata literal persist", - unboxinteger(rootobj.testliteraludata) == 71) - dotest("Udata special persist", - unboxboolean(rootobj.testspudata1) == true and - unboxboolean(rootobj.testspudata2) == false) - dotest("Shared upvalues ", - testcounter(rootobj.testsharedupval)) - dotest("Open upvalues ", - testuvinthread(rootobj.testuvinthread)) - dotest("Upvalue cycles ", - rootobj.testuvcycle()[1] == rootobj.testuvcycle()[2]) - dotest("__newindex metamethod", rootobj.testniinmt.a == 3) - dotest("Debug info ", (rootobj.testdebuginfo(2)) == "foo") - print() - if passed == total then - print("All tests passed.") - else - print(passed .. "/" .. total .. " tests passed.") - end -end - -infile, err = io.open("test.plh", "rb") -if infile == nil then - error("While opening: " .. (err or "no error")) -end - -buf, err = infile:read("*a") -if buf == nil then - error("While reading: " .. (err or "no error")) -end - -infile:close() - -rootobj = pluto.unpersist(perms, buf) - -test(rootobj) |