File Scoping Lua?

Started by
3 comments, last by PAndersson 11 years, 9 months ago
I'm failry new to using Lua in genral, but have looked into embedding. One issue I have encountered is that neither the luabind nor the lua api itself has the ability to call a function in a specific file, one can call a function by name but that has issues if two or more files has a function with the same name. That is something I would like to support however, so is it possible to file-scope lua? I was thinking giving each script file their own luaState in the game itself, am I right in assuming that that would work? Is there any other standard way of doing this?
Advertisement
Executing the contents of a file in a non-global environment might allow you to do this.

Caveat: It has been a while since I used Lua, and environments were handled differently in the older versions, so research the implications fully, don't take my word for it.

Executing the contents of a file in a non-global environment might allow you to do this.

Caveat: It has been a while since I used Lua, and environments were handled differently in the older versions, so research the implications fully, don't take my word for it.


Thank you, I seem to have difficulties changing the current enviroment though.
What kind of difficulties?

What kind of difficulties?


I might have midunderstood how this is done (as I said, inexperienced in Lua), buf if I assign a new table to _ENV, _ENV maintins the same table reference id as before.

This topic is closed to new replies.

Advertisement