Comments (3)
@fosskers I had the same problem, and found the solution in this comment: #259 (comment)
We need to let Fennel know that these globals [will] exist. To make your example work, I modified app.lua like this:
local globals = {"h1", "div"}
for key, _ in pairs(_G) do
table.insert(globals, key)
end
local app = require("fennel").install().dofile("app.fnl", {allowedGlobals = globals})
return app
EDIT: Unfortunately the above broke fennel.view
for me. In the end I reached for a heavier hammer:
local app = require("fennel").install().dofile("app.fnl", {allowedGlobals = false})
return app
from lapis.
the html
method creates a dynamic function scope that lazily creates these functions as you call them. (For this to work there must be no local variable that is shadowing the name of the function you want to call).
This is the exact line where the HTML tag function is generated: https://github.com/leafo/lapis/blob/master/lapis/html.moon#L180
Because these functions are bound to the background buffer that is accumulating the output, there is no way to access these function objects outside of the special rendering scope.
Does that help? If you could tell me more about what you're trying to do I might have a better answer for you.
from lapis.
Thanks! To the matter at hand then: I'm trying to use Lapis with Fennel and it seems that in its Fennel->Lua translation phase, it strictly considers which function symbols exist and which don't (rejecting the latter).
I have in a app.lua
:
local app = require("fennel").install().dofile("app.fnl")
return app
followed by this in Fennel:
(local lapis (require :lapis))
(local app (lapis.Application))
(fn index [self]
(self:html (fn []
(h1 {:class "header"} "Hello")
(div {:class "body"} "Welcome to my site!"))))
(app:match "/" index)
app
My server starts fine with lapis server
, but attempting to access localhost:8080/
gives this in my terminal:
2023/04/18 13:06:22 [error] 63794#0: *1 lua entry thread aborted: runtime error: app.fnl:10:16 Compile error: unknown identifier: h1
(h1 {:class "header"} "Hello")
* Try looking to see if there's a typo.
* Try using the _G table instead, eg. _G.h1 if you really want a global.
* Try moving this code to somewhere that h1 is in scope.
* Try binding h1 as a local in the scope of this code.
stack traceback:
coroutine 0:
[C]: in function 'require'
/home/colin/.luarocks/share/lua/5.1/lapis/init.lua:15: in function 'serve'
content_by_lua(nginx.conf.compiled:26):2: in main chunk, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"
2023/04/18 13:06:22 [error] 63794#0: *2 open() "/home/colin/code/fennel/lapit-test/static/favicon.ico" failed (2: No such file or directory), client: 127.0.0.1, server: , request: "GET /favicon.ico HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/"
It (re: the Fennel compiler) is unable to find the h1
, since it doesn't exist yet as you explained.
Any thoughts of how I could approach this better?
from lapis.
Related Issues (20)
- Warning: No Lua interpreter detected for version 5.4. Not creating ./lua.bat HOT 1
- Can I use "content" in etlua? HOT 1
- Missing deps HOT 3
- Error include module for lapis version 1.9.1 HOT 1
- Intermittent "405 Method Not Allowed" HOT 2
- version 1.11.0 route get/post bug? HOT 2
- CORS for localhost frontend? HOT 8
- Postgresql how to add default value current_date HOT 1
- luarocks install lapis did not see installed openssl HOT 5
- route name cannot be one of the paths HOT 2
- Specifying backend=pgmoon now required? HOT 1
- Value not available in sub-sub-template if render(..., {value = ...}) used in the template
- Default Route - Open Redirect HOT 1
- Module Migrations not found HOT 1
- Error when trying to start server HOT 3
- display "listening on ..." on startup HOT 2
- Loading static files like css with cqueues server HOT 2
- Database type could not be determined from configuration (postgres, mysql, sqlite)
- How to get client ip? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lapis.