lua-users home
lua-l archive

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

> For example, this script does nothing:
> "function main(arg)
> end"
> While this one does:
> "x = 4"

I wouldn't really consider the first example a script that does nothing.  It
defines a global called 'main' - it happens to be an empty function, but it
can still stomp over any other 'main' I might already have.

Basically both scripts re-define the values of global variables; whether
they are set to 4 or an empty function is beside the point.

In any case, it might be adequate for you to install a global metatable and
catch added globals.. though if you want to catch modified ones you'll need
to do the proxy table trick and switch the global environment.  This will
allow you to tell if the script has any side-effects (like modifying vars
etc), but will not help if you truly want to know if the script executes
meaningful code.

For example, 'print("Hello")' would execute code, but not modify anything in
global space, or have any side effects on the calling code.  Nor would
declaring locals etc.

Love, Light and Peace,
- Peter Loveday
Director of Development, eyeon Software

----- Original Message ----- 
From: "Ando Sonenblick" <>
To: "Lua list" <>
Sent: Thursday, August 21, 2003 1:48 PM
Subject: Detecting an "empty" script?

> Gang,
> I need to determine if a Lua script does something -- anything -- nor not.
> I know I can technically parse the text of the script to determine if it
> will do anything or not, but that seems like a lot of work trying to
> decipher things.
> Is there a way that Lua can be convinced to determine this for me?  I'm
> thinking that once the script is compiled, one could quickly scan it for
> "set" opcodes and such?
> Any thoughts?
> Thx,
> Ando
> -----------------
> SpriTec Software