mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
restore argument, make more moonscripty, add spec #176
This commit is contained in:
parent
f08477d3d6
commit
0ccd5e3ca4
@ -18,14 +18,30 @@ local dirsep, line_tables, create_moonpath, to_lua, moon_loader, loadstring, loa
|
||||
dirsep = "/"
|
||||
line_tables = require("moonscript.line_tables")
|
||||
create_moonpath = function(package_path)
|
||||
local moonpaths = { }
|
||||
local _list_0 = split(package.path, ";")
|
||||
local moonpaths
|
||||
do
|
||||
local _accum_0 = { }
|
||||
local _len_0 = 1
|
||||
local _list_0 = split(package_path, ";")
|
||||
for _index_0 = 1, #_list_0 do
|
||||
local _continue_0 = false
|
||||
repeat
|
||||
local path = _list_0[_index_0]
|
||||
local p = path:match("^(.-)%.lua$")
|
||||
if p then
|
||||
insert(moonpaths, p .. ".moon")
|
||||
local prefix = path:match("^(.-)%.lua$")
|
||||
if not (prefix) then
|
||||
_continue_0 = true
|
||||
break
|
||||
end
|
||||
local _value_0 = prefix .. ".moon"
|
||||
_accum_0[_len_0] = _value_0
|
||||
_len_0 = _len_0 + 1
|
||||
_continue_0 = true
|
||||
until true
|
||||
if not _continue_0 then
|
||||
break
|
||||
end
|
||||
end
|
||||
moonpaths = _accum_0
|
||||
end
|
||||
return concat(moonpaths, ";")
|
||||
end
|
||||
@ -134,5 +150,6 @@ return {
|
||||
dirsep = dirsep,
|
||||
dofile = dofile,
|
||||
loadfile = loadfile,
|
||||
loadstring = loadstring
|
||||
loadstring = loadstring,
|
||||
create_moonpath = create_moonpath
|
||||
}
|
||||
|
@ -13,10 +13,10 @@ line_tables = require "moonscript.line_tables"
|
||||
|
||||
-- create moon path package from lua package path
|
||||
create_moonpath = (package_path) ->
|
||||
moonpaths = {}
|
||||
for path in *split package.path, ";"
|
||||
p = path\match "^(.-)%.lua$"
|
||||
if p then insert moonpaths, p..".moon"
|
||||
moonpaths = for path in *split package_path, ";"
|
||||
prefix = path\match "^(.-)%.lua$"
|
||||
continue unless prefix
|
||||
prefix .. ".moon"
|
||||
concat moonpaths, ";"
|
||||
|
||||
to_lua = (text, options={}) ->
|
||||
@ -103,6 +103,6 @@ remove_loader = ->
|
||||
{
|
||||
_NAME: "moonscript"
|
||||
:insert_loader, :remove_loader, :to_lua, :moon_loader, :dirsep,
|
||||
:dofile, :loadfile, :loadstring
|
||||
:dofile, :loadfile, :loadstring, :create_moonpath
|
||||
}
|
||||
|
||||
|
8
spec/moonscript_spec.moon
Normal file
8
spec/moonscript_spec.moon
Normal file
@ -0,0 +1,8 @@
|
||||
-- moonscript module
|
||||
|
||||
describe "moonscript.base", ->
|
||||
it "should create moonpath", ->
|
||||
path = ";./?.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua;/usr/lib/lua/5.1/?.luac;/home/leafo/.luarocks/lua/5.1/?.lua"
|
||||
import create_moonpath from require "moonscript.base"
|
||||
assert.same "./?.moon;/usr/share/lua/5.1/?.moon;/usr/share/lua/5.1/?/init.moon;/home/leafo/.luarocks/lua/5.1/?.moon", create_moonpath(path)
|
||||
|
Loading…
Reference in New Issue
Block a user