Sign in to follow this  
PAndersson

File Scoping Lua?

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Executing the contents of a file in a [url=http://www.lua.org/manual/5.2/manual.html#2.2"]non-global environment[/url] might allow you to do this.

Caveat: It has been a while since I used Lua, and environments were [url="http://www.lua.org/manual/5.2/manual.html#8"]handled differently in the older versions[/url], so research the implications fully, don't take my word for it.

Share this post


Link to post
Share on other sites
[quote name='rip-off' timestamp='1342985520' post='4962012']
Executing the contents of a file in a [url="http://www.lua.org/manual/5.2/manual.html#2.2"]non-global environment[/url] might allow you to do this.

Caveat: It has been a while since I used Lua, and environments were [url="http://www.lua.org/manual/5.2/manual.html#8"]handled differently in the older versions[/url], so research the implications fully, don't take my word for it.
[/quote]

Thank you, I seem to have difficulties changing the current enviroment though.

Share this post


Link to post
Share on other sites
[quote name='rip-off' timestamp='1343061284' post='4962290']
What kind of difficulties?
[/quote]

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this