summary refs log tree commit diff stats
path: root/cratera.lua
diff options
context:
space:
mode:
Diffstat (limited to 'cratera.lua')
-rw-r--r--cratera.lua21
1 files changed, 17 insertions, 4 deletions
diff --git a/cratera.lua b/cratera.lua
index fabb371..46894c5 100644
--- a/cratera.lua
+++ b/cratera.lua
@@ -22,17 +22,30 @@ local parser = require "parser"
 local luatokens = require "luatokens"
 local compiler = require "compiler"
 
-local CRATERA_SEED = nil -- TODO
+local LUA_SIGNATURE = string.dump(function() end):sub(1,1)
 
-local function cratera_load(reader)
+local function cratera_load(reader, ...)
+    local chunkname, mode, env = ...
+    if type(reader) == "string" and reader:sub(1,1) == LUA_SIGNATURE then
+        -- bytecode
+        return (loadstring or load)(reader, ...)
+    end
     local f, s, i = parser.stream(luatokens.defs, reader)
+    if type(s[parser.DATA]) == "string" and s[parser.DATA]:sub(1,1) == LUA_SIGNATURE then
+        -- bytecode
+        local function fn()
+            fn = reader
+            return s[parser.DATA]
+        end
+        return (loadstring or load)(function() return fn() end, ...)
+    end
     local nl = 1
-    local otherstate = {}
+    local otherstate = {source=chunkname} -- FIXME
     local f, s, i = parser.stream(compiler.defs, function()
         local tokens
         repeat
             local pos, state, transemsg, etoken, estate = f(s, i)
-            otherstate.line = state.line
+            otherstate.linenumber = state.line
             i = pos
             if not i then return nil end
             if not state then error(transemsg) end