refreezed / luapreprocess Goto Github PK
View Code? Open in Web Editor NEWA small and straightforward Lua preprocessor with simple syntax.
Home Page: http://refreezed.com/luapreprocess/
License: MIT License
A small and straightforward Lua preprocessor with simple syntax.
Home Page: http://refreezed.com/luapreprocess/
License: MIT License
Hi, im doing some separation for my different builds. I have handler_dev.lua
and handler_test.lua
that I use depending on what I want to build.
Content of handler_dev.lua
:
_RELEASE = false
_REPORTING = false
_NETWORK = false
_ASSERT = true
_LOG_SAVE = false
require("handler")
return {}
Content of handler_test.lua
:
_RELEASE = true
_REPORTING = false
_NETWORK = false
_ASSERT = false
_LOG_SAVE = false
require("handler")
return {}
Now, handler.lua
is a file that contains all other metadata I need that is common to both of them, like:
_PLATFORM = "desktop"
_GAME_TITLE = "project name"
_GAME_SIZE = { x = 1024, y = 640 }
_GAME_BASE_SIZE = { x = 128, y = 32 }
_IDENTITY = "projectname"
_LOVE_VERSION = "11.3"
_GAME_VERSION = { 0, 0, 1 }
But having the require
gives this error:
Error @ output//error_handler.lua:139: 'end' expected (to close 'if' at line 134) near 'if'
--color.lua
local function convert(r, g, b)
return r/255, g/255, b/255 --it seems that only the r/255 is returned
end
--main/lua
!(@insert "color.lua")
local test = { !(convert(255, 255, 255)) }
print(unpack(test)) --prints only 1
Hi, still tinkering with this awesome lib when I've found out that
--src/main.lua2p
local test_module
!if _DEBUG then
test_module = require("src.test_module") --"src/test_module" does not work either
!end
--src/test_modules.lua2p
local test_module = {}
!if _DEBUG then
print(1)
!else
print(2)
!end
return test_module = {}
error is that src/test_module
could not be found.
Does this mean that I have change all required modules that use src/**
to use srcgen/**
?
Hi, parsing something this results to malformed string
error
local error_msg = format("Data integrity is not valid.\n
Please do not modify the files: '%s' and '%s'.\n
Please delete the files in '%s' and restart the game",
save_filename, key_filename, love.filesystem.getSaveDirectory())
Here's the output:
==============================================
= LuaPreprocess v1.11.0, 2020-08-09 12:08:54 =
==============================================
Processing 'test.lua2p'...
Error @ test.lua2p:1: [Tokenizer] Malformed string.
>
> local error_msg = format("Data integrity is not valid.\n
>--------------------------^
>
Making the string one-liner doesn't result to the error.
--from
!if _TEST then
print("test")
!end
--to
!if _TEST then print("test') !end
--or perhaps a different synax.
I'm wondering why there's nothing like
lua preprocess-cmd.lua input.lua output.lua -isdebug
It would be useful and more appropriate for usage to be able to pass meta information than to make a build system like the one in your löve's example (also check the comment I've made there)
I have looked at the examples and the lua file itself. I may have missed it.
Sent from my HUAWEI GR5 2017 using FastHub
does this already have something like this? Ive checked the wiki and havent found anything for it.
lua preprocess-cl.lua --handler=myHandler.lua src/main.lua2p ../output/src/
I have a handler.lua with:
_C_HSPEED = toLua("hspeed")
Which i use like local component = $_C_HSPEED
.
However, I also need to have something with !
prefix like : local n = "!hspeed"
Ive tried:
--handler.lua
function n(component) return "!" .. component end
with @@n($_C_HSPEED)
but it complains about the !
token as it outputs !"hspeed"
literally.
And yes, "!" .. $_C_HSPEED
works as it generates "!" .. "hspeed"
in the output file but this would be the last resort if no other way is possible
Hi, I am wondering if the lib already allows returning error code when a file can't be parsed (instead of just showing an error message)
My use case is that for my bash script, I want to catch that error and not continue running my build script if an error occurred.
example:
!(
local ids = {
"typewriter",
}
for _, v in ipairs(ids) do
local cname = v .. "_on_finish"
outputLua("Concord.component('" .. cname .. "', function(c, signal, delay, ...)\n")
outputLua("\t@@assert(type(signal) == 'string')\n")
outputLua("\t@@assert(type(delay) == 'delay')\n")
outputLua("\tc.signal = signal\n")
outputLua("\tc.delay = delay or 0\n")
outputLua("\tc.args = {...}\n")
outputLua("end)\n\n")
end
)
(removing the line with @@ works)
The desired generated code is:
Concord.component('typewriter_on_finish', function(c, signal, delay, ...)
@@assert(type(signal) == 'string')
@@assert(type(delay) == 'delay')
c.signal = signal
c.delay = delay or 0
c.args = {...}
end)
the @@assert
is a function defined in the handler.lua
:
function assert(cond, msg)
if _RELEASE then return "" end
msg = msg or string.format("%q", "Assertion failed: " .. cond)
return "if not (" .. cond .. ") then error(" .. msg ..") end"
end
the error is unexpected symbol near '@'
Hello, I would like to implement a macro definition feature similar to C++. Here is an example code. Could you please guide me on how to achieve this?
#define GIsShipping
#if GIsShipping then
#define Log(...) Log(...)
#else
#define Log(...)
#endif
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.