lua-users home
lua-l archive

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


> although this might work, I strongly recommend you rethink you design in Lua.  USE LUA IN THE WAY LUA IS.

Well, Lua the "the way it is", with no changes, means every variable written by any script will go into the same namespace, _G, and that's a pretty error prone thing.  There will be conflicts between names used by different scripts and objects, and it'll just be unworkable.

Using a namespace per script, lexically scoped, doesn't work well either, because each script can be used by many game objects, and there will be conficts between game objects using the same script.  Similar situation: it'll be a mess of defects.  I don't think reusing the same lua script for different game objects is so bad, really: there will be too many game objects to dupliate every script for each one, and anyway, the code doesn't change per object, so why should I duplicate it thusly?

So the only thing that made much sense to me was to use a dynamically scoped global environment.  I could turn off the global environment entirely, but that just makes script writers prefix every non-local they use with "something.myvar", which doesn't seem desirable either.

I couldn't think of any real alternatives to the approach I'm taking that didn't have drawbacks.  I do care about performance, but robustiness of scripts is an even higher priority than that, so I want to design for good encapsulation (and if I can figure out how to, for as much static checking as possible.  I found a web page talking about static checking tools for Lua, but haven't dug into it yet).