summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2024-05-26 13:06:12 -0300
committerSoniEx2 <endermoneymod@gmail.com>2024-05-26 13:06:12 -0300
commit9dea1c26b487ae723d99ba1e5e5887b09aec87dd (patch)
tree28a9c9cdf6ec10144d17d0249c69dcd8363f88d5
parent477d6b5eb7db81a07516667a891d8b433e9af4dd (diff)
Fix Lua 5.1 support and add tests
-rw-r--r--.gitignore2
-rwxr-xr-xbuild.sh5
-rw-r--r--cratera.lua (renamed from cratera/init.lua)2
-rw-r--r--testbc.lua29
4 files changed, 37 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..731e4eb
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/out/
+/testsdump.cratera
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..173fe8c
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+mkdir -p out/cratera/
+# worst tool for this job
+cp -r cratera/* out/cratera/
+cp cratera.lua out/cratera/init.lua
diff --git a/cratera/init.lua b/cratera.lua
index a07068e..6c0335b 100644
--- a/cratera/init.lua
+++ b/cratera.lua
@@ -36,7 +36,7 @@ local function cratera_load(reader, ...)
             fn = reader
             return s[parser.DATA]
         end
-        return (loadstring or load)(function() return fn() end, ...)
+        return (load)(function() return fn() end, ...)
     end
     local nl = 1
     local otherstate = {} -- needed to match linenumbers
diff --git a/testbc.lua b/testbc.lua
new file mode 100644
index 0000000..7b4a6e2
--- /dev/null
+++ b/testbc.lua
@@ -0,0 +1,29 @@
+local cratera = require "cratera"
+
+local function stream(filename, mode)
+    local file, err = io.open(filename, mode)
+    if not file then return nil, err end
+    return function()
+        local data, err = file:read(8192)
+        if not data then file:close() return nil, err end
+        return data
+    end
+end
+
+-- load tests, streaming
+local tests = assert(cratera.load(stream("tests.cratera", "rb")))
+
+-- dump tests
+local testsdump = string.dump(tests)
+
+-- check if cratera can load them
+assert(cratera.load(testsdump))()
+
+-- output to a file
+local file = io.open("testsdump.cratera", "wb")
+assert(file:write(testsdump))
+assert(file:flush())
+assert(file:close())
+
+-- load again, streaming, precompiled, and from a file
+assert(cratera.load(stream("testsdump.cratera", "rb")))()