lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



 
> > Now if you can make the IF ELSE switch based on --# as in
> > 
> > --#IF something
> >     print("something")
> > --#ELSE
> > --#    print("something else")
> > --#ENDIF
> > 
> 
> I would better use standard Lua syntax with a normal "if", but instead
> use a specially marked condition. Something like :
> ----
> function COMPILE_TIME(cond) return cond end
> 
> if COMPILE_TIME(condition) then
>   print("something")
> else
>   print("something else")
> end
> -----
> 
> The advantage is that it the script will run normally unprocessed, no
> matter what "condition" is.
> Now, since Lua language is not very difficult to parse, it should then
> not be a big problem to write a filter that looks for "if (not)?
> COMPILE_TIME(.*) then .* end" pattern, evaluate the constant condition,
> and outputs a scripts without those runtime tests.

Nice, I didn't think of that. But I would still prefer --# solution, as I
don't like preprocessor directives to blend in with regular code. They have
a different purpose, so I think they should stand out.

Thijs