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 = "/"
|
dirsep = "/"
|
||||||
line_tables = require("moonscript.line_tables")
|
line_tables = require("moonscript.line_tables")
|
||||||
create_moonpath = function(package_path)
|
create_moonpath = function(package_path)
|
||||||
local moonpaths = { }
|
local moonpaths
|
||||||
local _list_0 = split(package.path, ";")
|
do
|
||||||
|
local _accum_0 = { }
|
||||||
|
local _len_0 = 1
|
||||||
|
local _list_0 = split(package_path, ";")
|
||||||
for _index_0 = 1, #_list_0 do
|
for _index_0 = 1, #_list_0 do
|
||||||
|
local _continue_0 = false
|
||||||
|
repeat
|
||||||
local path = _list_0[_index_0]
|
local path = _list_0[_index_0]
|
||||||
local p = path:match("^(.-)%.lua$")
|
local prefix = path:match("^(.-)%.lua$")
|
||||||
if p then
|
if not (prefix) then
|
||||||
insert(moonpaths, p .. ".moon")
|
_continue_0 = true
|
||||||
|
break
|
||||||
end
|
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
|
end
|
||||||
return concat(moonpaths, ";")
|
return concat(moonpaths, ";")
|
||||||
end
|
end
|
||||||
@ -134,5 +150,6 @@ return {
|
|||||||
dirsep = dirsep,
|
dirsep = dirsep,
|
||||||
dofile = dofile,
|
dofile = dofile,
|
||||||
loadfile = loadfile,
|
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 moon path package from lua package path
|
||||||
create_moonpath = (package_path) ->
|
create_moonpath = (package_path) ->
|
||||||
moonpaths = {}
|
moonpaths = for path in *split package_path, ";"
|
||||||
for path in *split package.path, ";"
|
prefix = path\match "^(.-)%.lua$"
|
||||||
p = path\match "^(.-)%.lua$"
|
continue unless prefix
|
||||||
if p then insert moonpaths, p..".moon"
|
prefix .. ".moon"
|
||||||
concat moonpaths, ";"
|
concat moonpaths, ";"
|
||||||
|
|
||||||
to_lua = (text, options={}) ->
|
to_lua = (text, options={}) ->
|
||||||
@ -103,6 +103,6 @@ remove_loader = ->
|
|||||||
{
|
{
|
||||||
_NAME: "moonscript"
|
_NAME: "moonscript"
|
||||||
:insert_loader, :remove_loader, :to_lua, :moon_loader, :dirsep,
|
: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