mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
update load functions for 5.2
This commit is contained in:
parent
3ec2f18b6b
commit
cbf624d0f6
@ -1 +1 @@
|
||||
require "moonscript.init"
|
||||
return require "moonscript.init"
|
||||
|
@ -1,10 +1,10 @@
|
||||
local compile = require("moonscript.compile")
|
||||
local parse = require("moonscript.parse")
|
||||
local concat, insert = table.concat, table.insert
|
||||
local split, dump
|
||||
local split, dump, get_options, unpack
|
||||
do
|
||||
local _table_0 = require("moonscript.util")
|
||||
split, dump = _table_0.split, _table_0.dump
|
||||
split, dump, get_options, unpack = _table_0.split, _table_0.dump, _table_0.get_options, _table_0.unpack
|
||||
end
|
||||
local lua = {
|
||||
loadstring = loadstring
|
||||
@ -73,10 +73,9 @@ if not (_G.moon_no_loader) then
|
||||
init_loader()
|
||||
end
|
||||
local loadstring
|
||||
loadstring = function(str, chunk_name, options)
|
||||
if options == nil then
|
||||
options = nil
|
||||
end
|
||||
loadstring = function(...)
|
||||
local options, str, chunk_name, mode, env = get_options(...)
|
||||
chunk_name = chunk_name or "=(moonscript.loadstring)"
|
||||
local passed, code, ltable = pcall(function()
|
||||
return to_lua(str, options)
|
||||
end)
|
||||
@ -86,24 +85,24 @@ loadstring = function(str, chunk_name, options)
|
||||
if chunk_name then
|
||||
line_tables[chunk_name] = ltable
|
||||
end
|
||||
return lua.loadstring(code, chunk_name or "=(moonscript.loadstring)")
|
||||
return (lua.loadstring or lua.load)(code, chunk_name, unpack({
|
||||
mode,
|
||||
env
|
||||
}))
|
||||
end
|
||||
local loadfile
|
||||
loadfile = function(fname, options)
|
||||
if options == nil then
|
||||
options = nil
|
||||
end
|
||||
loadfile = function(fname, ...)
|
||||
local file, err = io.open(fname)
|
||||
if not file then
|
||||
return nil, err
|
||||
end
|
||||
local text = assert(file:read("*a"))
|
||||
file:close()
|
||||
return loadstring(text, fname, options)
|
||||
return loadstring(text, fname, ...)
|
||||
end
|
||||
local dofile
|
||||
dofile = function(fname, options)
|
||||
local f = assert(loadfile(fname))
|
||||
dofile = function(...)
|
||||
local f = assert(loadfile(...))
|
||||
return f()
|
||||
end
|
||||
return {
|
||||
|
@ -3,7 +3,7 @@ compile = require "moonscript.compile"
|
||||
parse = require "moonscript.parse"
|
||||
|
||||
import concat, insert from table
|
||||
import split, dump from require "moonscript.util"
|
||||
import split, dump, get_options, unpack from require "moonscript.util"
|
||||
|
||||
lua = :loadstring
|
||||
|
||||
@ -57,24 +57,28 @@ init_loader = ->
|
||||
|
||||
init_loader! unless _G.moon_no_loader
|
||||
|
||||
loadstring = (str, chunk_name, options=nil) ->
|
||||
loadstring = (...) ->
|
||||
options, str, chunk_name, mode, env = get_options ...
|
||||
chunk_name or= "=(moonscript.loadstring)"
|
||||
|
||||
passed, code, ltable = pcall -> to_lua str, options
|
||||
if not passed
|
||||
error chunk_name .. ": " .. code, 2
|
||||
|
||||
line_tables[chunk_name] = ltable if chunk_name
|
||||
lua.loadstring code, chunk_name or "=(moonscript.loadstring)"
|
||||
-- the unpack prevents us from passing nil
|
||||
(lua.loadstring or lua.load) code, chunk_name, unpack { mode, env }
|
||||
|
||||
loadfile = (fname, options=nil) ->
|
||||
loadfile = (fname, ...) ->
|
||||
file, err = io.open fname
|
||||
return nil, err if not file
|
||||
text = assert file\read "*a"
|
||||
file\close!
|
||||
loadstring text, fname, options
|
||||
loadstring text, fname, ...
|
||||
|
||||
-- throws errros
|
||||
dofile = (fname, options) ->
|
||||
f = assert loadfile fname
|
||||
dofile = (...) ->
|
||||
f = assert loadfile ...
|
||||
f!
|
||||
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user