Page 2 of 8

Re: LuaPreprocess

Posted: Sun Mar 08, 2020 5:08 pm
by monolifed
I found this to be more intuitive than the others

Re: LuaPreprocess

Posted: Mon Mar 09, 2020 6:31 am
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. :)

Re: LuaPreprocess

Posted: Sat Sep 26, 2020 11:35 pm
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...

Re: LuaPreprocess

Posted: Sun Sep 27, 2020 11:12 am
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!

Re: LuaPreprocess

Posted: Sun Sep 27, 2020 2:41 pm
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 :)

Re: LuaPreprocess

Posted: Sun Sep 27, 2020 4:52 pm
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.

Re: LuaPreprocess

Posted: Mon Sep 28, 2020 1:21 am
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.

Re: LuaPreprocess

Posted: Tue Sep 29, 2020 7:36 pm
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.

Re: LuaPreprocess

Posted: Mon Jan 11, 2021 7:13 am
by ReFreezed
Update 1.11.2

Changes since 1.11.1:

Library:
  • Fixed parsing of numbers ending with a point.
Command line program:

Re: LuaPreprocess

Posted: Wed Jan 13, 2021 1:36 pm
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.