Sign in to follow this  
triqer

Lua 'require' works normally, but not in app

Recommended Posts

So I use Lua's require to grab functions from another Lua file. I've tested to make sure the functions are accessible and they are when I'm just using Lua. However, Lua is embedded in an app written in C++. GameObjects use scripts for their behavior. When the app runs, for some reason the 'require' part seems to fail since none of the behavior occurs when it is in, but it's fine without it. I have no idea what the problem is. Is the app for some reason not recognizing that the script exists? In our GameObject, we call luaL_dofile for the state, and the script for the object. Would we need to do this for the GameObjectUtility file (the one that I'm trying to 'require') as well? Any help is appreciated. Thanks.

Share this post


Link to post
Share on other sites
When using require Lua does a search of several paths to try and find the file. Some are hard coded into Lua itself but the most important one is the one relative to the executable. Lua generates an error when require fails which you can print out and it will tell u all the paths it tried.

Check to see if the relative path matches in both environments so require can find the Lua file.

Good Luck.

-ddn

Share this post


Link to post
Share on other sites
Thanks, this pointed me in the right direction.

I ended up solving the problem by setting the package path to...


package.path = package.path .. ";Content/Core/Scripts/?.lua"

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