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 compile = require("moonscript.compile")
|
||||||
local parse = require("moonscript.parse")
|
local parse = require("moonscript.parse")
|
||||||
local concat, insert = table.concat, table.insert
|
local concat, insert = table.concat, table.insert
|
||||||
local split, dump
|
local split, dump, get_options, unpack
|
||||||
do
|
do
|
||||||
local _table_0 = require("moonscript.util")
|
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
|
end
|
||||||
local lua = {
|
local lua = {
|
||||||
loadstring = loadstring
|
loadstring = loadstring
|
||||||
@ -73,10 +73,9 @@ if not (_G.moon_no_loader) then
|
|||||||
init_loader()
|
init_loader()
|
||||||
end
|
end
|
||||||
local loadstring
|
local loadstring
|
||||||
loadstring = function(str, chunk_name, options)
|
loadstring = function(...)
|
||||||
if options == nil then
|
local options, str, chunk_name, mode, env = get_options(...)
|
||||||
options = nil
|
chunk_name = chunk_name or "=(moonscript.loadstring)"
|
||||||
end
|
|
||||||
local passed, code, ltable = pcall(function()
|
local passed, code, ltable = pcall(function()
|
||||||
return to_lua(str, options)
|
return to_lua(str, options)
|
||||||
end)
|
end)
|
||||||
@ -86,24 +85,24 @@ loadstring = function(str, chunk_name, options)
|
|||||||
if chunk_name then
|
if chunk_name then
|
||||||
line_tables[chunk_name] = ltable
|
line_tables[chunk_name] = ltable
|
||||||
end
|
end
|
||||||
return lua.loadstring(code, chunk_name or "=(moonscript.loadstring)")
|
return (lua.loadstring or lua.load)(code, chunk_name, unpack({
|
||||||
|
mode,
|
||||||
|
env
|
||||||
|
}))
|
||||||
end
|
end
|
||||||
local loadfile
|
local loadfile
|
||||||
loadfile = function(fname, options)
|
loadfile = function(fname, ...)
|
||||||
if options == nil then
|
|
||||||
options = nil
|
|
||||||
end
|
|
||||||
local file, err = io.open(fname)
|
local file, err = io.open(fname)
|
||||||
if not file then
|
if not file then
|
||||||
return nil, err
|
return nil, err
|
||||||
end
|
end
|
||||||
local text = assert(file:read("*a"))
|
local text = assert(file:read("*a"))
|
||||||
file:close()
|
file:close()
|
||||||
return loadstring(text, fname, options)
|
return loadstring(text, fname, ...)
|
||||||
end
|
end
|
||||||
local dofile
|
local dofile
|
||||||
dofile = function(fname, options)
|
dofile = function(...)
|
||||||
local f = assert(loadfile(fname))
|
local f = assert(loadfile(...))
|
||||||
return f()
|
return f()
|
||||||
end
|
end
|
||||||
return {
|
return {
|
||||||
|
@ -3,7 +3,7 @@ compile = require "moonscript.compile"
|
|||||||
parse = require "moonscript.parse"
|
parse = require "moonscript.parse"
|
||||||
|
|
||||||
import concat, insert from table
|
import concat, insert from table
|
||||||
import split, dump from require "moonscript.util"
|
import split, dump, get_options, unpack from require "moonscript.util"
|
||||||
|
|
||||||
lua = :loadstring
|
lua = :loadstring
|
||||||
|
|
||||||
@ -57,24 +57,28 @@ init_loader = ->
|
|||||||
|
|
||||||
init_loader! unless _G.moon_no_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
|
passed, code, ltable = pcall -> to_lua str, options
|
||||||
if not passed
|
if not passed
|
||||||
error chunk_name .. ": " .. code, 2
|
error chunk_name .. ": " .. code, 2
|
||||||
|
|
||||||
line_tables[chunk_name] = ltable if chunk_name
|
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
|
file, err = io.open fname
|
||||||
return nil, err if not file
|
return nil, err if not file
|
||||||
text = assert file\read "*a"
|
text = assert file\read "*a"
|
||||||
file\close!
|
file\close!
|
||||||
loadstring text, fname, options
|
loadstring text, fname, ...
|
||||||
|
|
||||||
-- throws errros
|
-- throws errros
|
||||||
dofile = (fname, options) ->
|
dofile = (...) ->
|
||||||
f = assert loadfile fname
|
f = assert loadfile ...
|
||||||
f!
|
f!
|
||||||
|
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user