lua-users home
lua-l archive

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


> -----Original Message-----
> From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org]
> On Behalf Of David Collier
> Sent: dinsdag 2 oktober 2012 18:36
> To: lua-l@lists.lua.org
> Subject: Lua code generation and optimisation
> 
> I'm thinking about code size.
> 
> If I write
> 
>  if CheckCarefully and fred > 3
>  then
>      print("help fred is >3 which is a very bad idea in our case")
>      return
>  else
>      <whatever using fred>
>  end
> 
> Can I set up the value of CheckCarefully so that the compiler can omit
> the print and omit storing the error string.
> 
> Or will it always create the strings in the bytecode?

I think it will, its a dynamic language, so "CheckCarefully" could be
redefined at any time. Consider;
    local a = "Wildly"
    if something then a = "Carefully" end
    mytable["Check".. a] = nil

if this is supposed to run correctly, then the code must be compiled.

> 
> If this won't work, anyone got a good way to have code and strings in
> during testing phase and omitted in deployed code?
> The C preprocessor would do it, but I hate the idea of using facilities
> from another language.

iirc Steve Donovan created a Lua Preprocessor.

Also relevant maybe;
http://permalink.gmane.org/gmane.comp.lang.lua.general/93816