Add fennel loader

This commit is contained in:
Talia 2024-08-20 15:39:13 +02:00
parent 89b53d1aa2
commit f99667fbf5
4 changed files with 30 additions and 1 deletions

View file

@ -1,5 +1,8 @@
return {
_all = {
lpath = "?.lua;?/init.lua"
}
};
core = {
recursive = false
};
}

18
glass/fennel.lua Normal file
View file

@ -0,0 +1,18 @@
--- Loader for Fennel files
-- @module glass.fennel
local fennel = require "fennel"
local read = require 'glass.raw'
--- Loads and compiles a Fennel file and runs it.
-- Returns the result of running the Fennel file.
-- If running the code immediately is not desired,
-- it has to be returned as a function.
-- @return The result of the Fennel file after running it
-- @function load
return function(file)
local success, raw = read(file..'.fnl')
if success then
return true, fennel.eval(raw)
end
end

View file

@ -0,0 +1,6 @@
describe 'fennel loader', ->
before_each -> export loader = require 'glass.fennel'
it 'loads Fennel files', ->
success, result = loader 'spec/fixtures/test'
assert.true success
assert.same { foo: 'bar', tab: {} }, result

2
spec/fixtures/test.fnl vendored Normal file
View file

@ -0,0 +1,2 @@
{"foo" "bar"
"tab" []}