Jump to content




CLua - Conditional Lua Compilation


11 replies to this topic

#1 skwerlman

  • Members
  • 163 posts
  • LocationPennsylvania

Posted 01 June 2014 - 06:33 AM

CLua
A Conditional Lua compiler!

Currently on version: 2.0.0

Now available through MPT! (currently on version 2.0.0-p42; usually updated within 15 minutes of main version)

What does it do?
Spoiler

Why'd you make it?
Spoiler

How do I use it?
Spoiler

When should I use it?
Spoiler

When shouldn't I use it?
Spoiler

How do I install it?
Spoiler

How do I uninstall it?
Spoiler

What's next?
Spoiler

What if there's an issue?
Spoiler

Can you add...?
Spoiler

Known bugs
Spoiler

I'd like to submit a library...
Spoiler

Important notes!
Spoiler

Examples!
Spoiler

Changelog
Spoiler

Edited by skwerlman, 26 July 2014 - 05:29 AM.


#2 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 01 June 2014 - 02:49 PM

I like it. I use C# a lot and it also has conditional compilation symbols. My one question is why conditional? Because we are not compiling for multiple platforms (Ok, we have coloured or not, pocket, turtle or computer) when would we choose to use it. I could actually find this useful for coloured/not compilation. I though about implementing it in PPI but looks like you have done a better job. Two suggestions though:
  • #ELSE statement. For instance you could have:
    		#IFDEF
    		print("Hello")
    		#ELSE
    		print("Hi")
    		#ENDIFDEF
    		
    I know you could have an #IFDEF ... #ENDIFDEF, #IFNDEF ... #ENDIFNDEF but I think this would be easier.
  • Be able to define variables in the command line: clua --var=thing This would make it more convenient than editing the files. How do you choose the output file though?
You can also do pastebin run zPMasvZ2 instead, but this is just a matter of preference (and doesn't work pre 1.6).

I'm so happy that someone has developed the idea of PPI further.

Edited by SquidDev, 01 June 2014 - 02:50 PM.


#3 skwerlman

  • Members
  • 163 posts
  • LocationPennsylvania

Posted 01 June 2014 - 03:24 PM

View PostSquidDev, on 01 June 2014 - 02:49 PM, said:

I like it. I use C# a lot and it also has conditional compilation symbols. My one question is why conditional? Because we are not compiling for multiple platforms (Ok, we have coloured or not, pocket, turtle or computer) when would we choose to use it. I could actually find this useful for coloured/not compilation. I though about implementing it in PPI but looks like you have done a better job.
Well, while we don't have multiple platforms, we do have multiple environments. Certain programs expose APIs, such as in OneOS. Conditional compiling lets you write something like Environment.lua that contains a bunch of #DEFINEs to specify what you expect to your environment to look like. (or after I add those command line args you suggested, it could be compiled dynamically)

View PostSquidDev, on 01 June 2014 - 02:49 PM, said:

Two suggestions though:
  • #ELSE statement. For instance you could have:
    					#IFDEF
    					print("Hello")
    					#ELSE
    					print("Hi")
    					#ENDIFDEF
    					
    I know you could have an #IFDEF ... #ENDIFDEF, #IFNDEF ... #ENDIFNDEF but I think this would be easier.
  • Be able to define variables in the command line: clua --var=thing This would make it more convenient than editing the files. How do you choose the output file though?
1. First, IFDEF needs a flag... Second, yes ELSE is a very good idea. Thats going right onto my TODO list.
2. That's a really good idea. I'll definitely add command line arguments. It'll make logging make more sense (a third arg of ANYTHING (even false) will enable logging).

The output file is the second argument passed to clua. As it stands now, usage is clua <input> <output> <logging>
I thought I put that in the post...
EDIT: Wow that was a massive derp... Fixed

View PostSquidDev, on 01 June 2014 - 02:49 PM, said:


You can also do pastebin run zPMasvZ2 instead, but this is just a matter of preference (and doesn't work pre 1.6).
I included the instructions the way I did because in future versions the installer will double as an updater

View PostSquidDev, on 01 June 2014 - 02:49 PM, said:

I'm so happy that someone has developed the idea of PPI further.
It wouldn't have happened without PPI :)

Edited by skwerlman, 01 June 2014 - 03:44 PM.


#4 skwerlman

  • Members
  • 163 posts
  • LocationPennsylvania

Posted 04 June 2014 - 09:51 PM

I'm considering adding a directive, #DEFONCE, which will define a flag and also set it in the warning table, so the compiler will error if anything tries to #DEFINE it later. Thoughts?

#5 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 05 June 2014 - 07:00 AM

View Postskwerlman, on 04 June 2014 - 09:51 PM, said:

I'm considering adding a directive, #DEFONCE, which will define a flag and also set it in the warning table, so the compiler will error if anything tries to #DEFINE it later. Thoughts?

When you you use that? I just can't see any practical applications of it, would defining it twice break your code or something?

#6 skwerlman

  • Members
  • 163 posts
  • LocationPennsylvania

Posted 05 June 2014 - 05:45 PM

View PostSquidDev, on 05 June 2014 - 07:00 AM, said:

View Postskwerlman, on 04 June 2014 - 09:51 PM, said:

I'm considering adding a directive, #DEFONCE, which will define a flag and also set it in the warning table, so the compiler will error if anything tries to #DEFINE it later. Thoughts?

When you you use that? I just can't see any practical applications of it, would defining it twice break your code or something?
It can be used in libraries that define functions to indicate that loading it more than once is not allowed.
Basically, it helps enforce good library writing/loading standards.
It also completely exempts a file from any loop detection (which may be more complex later) potentially making compilation faster.

Edited by skwerlman, 09 June 2014 - 07:31 PM.


#7 skwerlman

  • Members
  • 163 posts
  • LocationPennsylvania

Posted 10 June 2014 - 07:35 AM

CLua version 1.1.1 is now available! This update fixes issues with logging and the SNIPPET directive, and includes some more prep for libraries (and actual, working libraries if you installed using MPT).
I also fixed an issue which made the MPT version incompatible with X System (the OS MPT was written for).
Finally, and perhaps most importantly, I cut the console output down from pages to lines.
See the changelog for full info.

Fixing IFDEF and IFNDEF is next on my list, but I can't seem to find the code that was giving me issues... I'll put it on hold for now, and work on command line arguments instead.

EDIT:
Clua version 1.2.0 is now available! This version adds support for command line arguments! I added three args: log, exec, and define. log enables logging (wow, so informative!), exec runs whatever code is passed to it, and define sets the flag passed to it. All of these args can be supplied multiple times (though I don't think you'll need to pass log more than once...). I also added the two MPT-only libraries to the pastebin version.
As always, see the changelog for full info.

I'm still trying reproduce that IFDEF bug, but I haven't succeeded... Maybe I dreamt it? Since I can't reproduce it yet, I'll work on adding some more libraries for now. Mikk809h's LogAPI is next.

Oh, and I added a compilation timer. It's mostly for me benchmarking my code, but I bet someone out there will find it useful.

Edited by skwerlman, 11 June 2014 - 03:57 AM.


#8 skwerlman

  • Members
  • 163 posts
  • LocationPennsylvania

Posted 13 June 2014 - 06:26 AM

CLua version 1.3.0 is now available! This version adds 5 new PPDs, (slightly) better logging, and fixes a serious bug in the exec option.
Oh, and a TON of error checking (mostly in the new PPDs + exec)
The new PPDs:
#EXEC <code> - Basically the same as the --exec option, but a PPD
#IFVAR <variable> - Checks whether a variable is defined. Syntax is similar to #IFDEF.
#ENDIFVAR - Ends an #IFVAR block
#IFNVAR <variable> - Checks whether a variable is undefined. Syntax is similar to #IFNDEF.
#ENDIFNVAR - Ends an #IFNVAR block

I've given up on that IFDEF bug, but if anyone can manage to reproduce it, I'll see if I can fix it.

#9 skwerlman

  • Members
  • 163 posts
  • LocationPennsylvania

Posted 23 June 2014 - 06:19 AM

Forgot to mention that 1.4.0 is out!

I fixed that one IFDEF bug. It would happen when an #END... directive was either the last line or the second to last line followed by a blank line. The corresponding #IF... would never reach it since it would think it ran out of file before it reached the actual last line.

I added ten new command line options, and imporved the usage formatting. Also, the usage got kinda long, so I'm now using pagedprint.

I also added two new libraries, SPLASH and JSON.
JSON allows you to convert JSON files into Lua tables and vice versa.
SPLASH allows you to read and write to a JSON formatted list of splash texts, as well as grab a random, persistent splash text.

I fixed a couple other minor bugs, and made some minor changes.

And, as seems to be the case with every update, I improved logging. Actually, it changed a lot this time.

See the CL for more info.

#10 skwerlman

  • Members
  • 163 posts
  • LocationPennsylvania

Posted 25 June 2014 - 02:38 AM

Version 1.5.0 is out!

This version adds a bunch of features to make licensing requirements easy. With a single line of code, you can pick a license for your program, and you never need to worry about fulfilling the requirements of the modules you're using, since CLua takes care of it for you.

This version also adds the ability to have lines of code generated at compile time.

As always, there's some more improvements to logging. (I'm beginning to think I have an issue... :P)
The CL has more info.

Edited by skwerlman, 25 June 2014 - 02:39 AM.


#11 skwerlman

  • Members
  • 163 posts
  • LocationPennsylvania

Posted 26 July 2014 - 05:07 AM

Version 2.0.0 is out!

This version fixes all known bugs, adds a couple nifty new options, expands the syntax of --define and makes a couple other tweaks and improvements.
As always, the changelog has a much more descriptive list of changes/fixes/additions.

I'll be updating the MPT repo soon, though I'm considering dropping it, as MPT's development seems to have stalled.

I'm looking for library submissions now. If you'd like your library to be included with CLua, send me a PM with the license and a link to the source and I'll see about adding it.

Oh, yeah, I also wrote an optional test suite for CLua. It's available on the Github. Drop those files into /clua/test/ and run selftest.lua to make sure your copy is working right. It's useful if you're messing with the source code, since it tests every directive CLua provides, plus all of its libraries.

#12 0099

  • Members
  • 52 posts

Posted 13 August 2014 - 04:21 PM

It reminds me of one of my first Lua projects - it was a custom preprocessor for C, so instead of writing large amount of C code, I could leave a Lua script at that point, which will automatically generate it. It turned out to be useful, especially commands "rememer this struct" and "write remembered struct into a file field-by-field".





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users