LuaPreprocess - straightforward preprocessor with simple syntax

Showcase your libraries, tools and other projects that help your fellow love users.
monolifed
Party member
Posts: 188
Joined: Sat Feb 06, 2016 9:42 pm

Re: LuaPreprocess

Post by monolifed »

I found this to be more intuitive than the others
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: LuaPreprocess

Post by ReFreezed »

ingsoc451 wrote: Sun Mar 08, 2020 5:08 pm I found this to be more intuitive than the others
I'm glad you think so. :)
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: LuaPreprocess

Post by ReFreezed »

Update 1.11.1

Changes since 1.11:

Library:
  • Huge numbers are now outputted as '1/0' instead of 'math.huge'.
  • Fixed newToken("pp_keyword",...) not accepting all preprocessor keywords.
  • Better error message for unescaped newlines in string literals.
Other:
  • Preprocess.cmd returns %ERRORLEVEL%.
----
More updates have been made since the first release. I'm not sure why I didn't post anything about them here...
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: LuaPreprocess

Post by ivan »

My gut reaction is that adding a preprocessing phase to Lua unnecessarily increases the complexity.

Personally, I find it easier to just hijack existing functions like so:

Code: Select all

if DEV_MODE then
  -- inject debug features to "print"
  devlog = {}
  local _print = print
  function print(sz)
    -- append to the the debug log here
    table.insert(devlog, sz)
    _print(sz)
  end
end
I could be wrong, but it's an interesting library and kudos for attempting this in pure Lua.
Your code looks very much like C and I believe it could be simplified using pattern matching.
Don't want to criticize this project too much, and it's a decent try. Good luck!
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: LuaPreprocess

Post by ReFreezed »

@ivan
I don't agree that unnecessary complexity is being added. I've used the library in multiple projects now and I've found that it makes a bunch of different tasks easier to do, and other tasks that weren't even possible before now becoming possible, without saying anything specific. (That example doesn't really demonstrate what I use preprocessing for.)

I'm not sure what you mean by the pattern matching part. The library is using pattern matching to match Lua tokens when parsing. Sure, the library could be simplified and optimized in general but I don't think it's bad as it is.

Thanks for the good luck :)
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: LuaPreprocess

Post by ivan »

Precropressing is basically one language on top of another so it's definately more complicated than just using Lua. Preprocessing bugs are notoriously hard to debug in C/C++ so I would disagree with you there.
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: LuaPreprocess

Post by ReFreezed »

I know what you mean, but unlike C/C++ there's only one language here. There are other preprocessors for Lua that has like a separate language for the "metaprogram" but that is something I specifically wanted to avoid. It's all Lua here. Another difference to C/C++ is that actual human-readable Lua code is being generated. If there's an error then it's easy to look at the outputted code.

I just think preprocessing is a powerful tool that, like any other tool, can be misused. The things in my metaprogram aren't very complex compared to the rest of the program (especially in games which are often complex systems by nature). Here's a comparison I'd like to make with something else... In object-oriented systems, class inheritance can create a lot of complexity if it's too deep and tangled, but if the inheritance is restricted to only one level deep in most places then inheritance isn't a problem anymore. The metaprogram could create a mess, but if you try to keep things simple then there are real benefits that can be made (like overall tidier code, or speed benefits at runtime in the final program).

Note that I don't think having a preprocessing phase necessarily makes things less complicated, but if preprocessing isn't used to accomplish a certain task then the complexity has to exist elsewhere to create the same desired outcome, and there's nothing that says things will be less complex at that point either. Use the right tool for the job.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: LuaPreprocess

Post by pgimeno »

ReFreezed wrote:Use the right tool for the job.
This sums it up pretty concisely. If you don't see a need for it, maybe you don't have one. When you need it, it's there for you.

There can be many uses for a preprocessor. One application that comes to mind is creating a demo version of a program without including the code for the full version. It might be possible to split that code into other files and invoke it conditionally, and omit these files in the demo, but that separation could be artificial and inconvenient.
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: LuaPreprocess

Post by ReFreezed »

Update 1.11.2

Changes since 1.11.1:

Library:
  • Fixed parsing of numbers ending with a point.
Command line program:
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: LuaPreprocess

Post by pgimeno »

I don't understand the difference between these two:

Code: Select all

!!local TWO_PI = 2 * math.pi

local TWO_PI = !(2 * math.pi)
Can you explain? I'm having trouble understanding why !! is necessary or convenient.
Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot], Semrush [Bot] and 13 guests