From 4b365cdab1296bc88509c6f8610318adefb0ef0e Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Tue, 30 Jul 2019 21:12:16 -0300 Subject: It... kinda works? --- cratera.lua | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'cratera.lua') 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 -- cgit 1.4.1