# Lua 'require' works normally, but not in app

This topic is 2981 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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"

• 10
• 16
• 14
• 18
• 15