Luainterface 5.1 get all used globals for a script

342 views Asked by At

Is there anyway to get a list of all the names of used globals?

One way is to not load any globals, and then execute the script. let it crash and parse the exception for the name.. very ugly...

1

There are 1 answers

1
Bosak On

Yes the Lua class has a property called Globals witch is IEnumerable<string> so you can do something like this:

public static IEnumerable<string> GetGlobalsFromFile(string fileName)
{
     using (Lua lua = new Lua())
     {
          lua.DoFile(filename);
          foreach(string global in lua.Globals)
               yeld return global;
     }
}

What this method does is it executes a sript and returns all the globas in the file.