Fixing registration of package path.
This commit is contained in:
		
							parent
							
								
									d2458f3169
								
							
						
					
					
						commit
						fa050ad616
					
				| @ -33,8 +33,7 @@ void LUA_print(T number) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Check if the lua function <name> is defined
 | // Check if the lua function <name> is defined
 | ||||||
| bool lua_function_exists(lua_State* lua_state, const char* name) | inline bool lua_function_exists(lua_State* lua_state, const char* name) { | ||||||
| { |  | ||||||
|     luabind::object g = luabind::globals(lua_state); |     luabind::object g = luabind::globals(lua_state); | ||||||
|     luabind::object func = g[name]; |     luabind::object func = g[name]; | ||||||
|     return func && (luabind::type(func) == LUA_TFUNCTION); |     return func && (luabind::type(func) == LUA_TFUNCTION); | ||||||
| @ -42,13 +41,12 @@ bool lua_function_exists(lua_State* lua_state, const char* name) | |||||||
| 
 | 
 | ||||||
| // Add the folder contain the script to the lua load path, so script can easily require() other lua scripts inside that folder, or subfolders.
 | // Add the folder contain the script to the lua load path, so script can easily require() other lua scripts inside that folder, or subfolders.
 | ||||||
| // See http://lua-users.org/wiki/PackagePath for details on the package.path syntax.
 | // See http://lua-users.org/wiki/PackagePath for details on the package.path syntax.
 | ||||||
| void luaAddScriptFolderToLoadPath(lua_State* myLuaState, const char* fileName) { | inline void luaAddScriptFolderToLoadPath(lua_State* myLuaState, const char* fileName) { | ||||||
|     const boost::filesystem::path profilePath( fileName ); |     const boost::filesystem::path profilePath( fileName ); | ||||||
|     if( !profilePath.parent_path().empty() ) { |     std::string folder = profilePath.parent_path().string(); | ||||||
|         const std::string folder = profilePath.parent_path().string(); |     //TODO: This code is most probably not Windows safe since it uses UNIX'ish path delimiters
 | ||||||
|         const std::string luaCode = "package.path = \"" + folder + "/?.lua;\" .. package.path"; |     const std::string luaCode = "package.path = \"" + folder + "/?.lua;profiles/?.lua;\" .. package.path"; | ||||||
|         luaL_dostring( myLuaState, luaCode.c_str() ); |     luaL_dostring( myLuaState, luaCode.c_str() ); | ||||||
|     } |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #endif /* LUAUTIL_H_ */ | #endif /* LUAUTIL_H_ */ | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user