当前位置: 首页 > 工具软件 > OpenLua > 使用案例 >

cannot open tolua.lua: No such file or directory

朱慈
2023-12-01

项目场景:

`提示:cannot open tolua.lua: No such file or directorytolua

确定有相关文件,但是在安卓手机报错没找到相关文件


问题描述

报错:cannot open tolua.lua: No such file or directorytolua

LuaException: cannot open tolua.lua: No such file or directory
no file './tolua.lua'
no file '/usr/local/share/luajit-2.1.0-beta3/tolua.lua'
no file '/usr/local/share/lua/5.1/tolua.lua'
no file '/usr/local/share/lua/5.1/tolua/init.lua'

原因分析:

提示:路径不对,查找不到:

LuaFileUtils.cs 函数FindFile无法查找到数据,LuaConst.cs 是系统路基脚本

public static class LuaConst
{
    public static string luaDir = Application.dataPath + "/LuaFramework/Lua";                //lua逻辑代码目录
    public static string toluaDir = Application.dataPath + "/LuaFramework/ToLua/Lua";        //tolua lua文件目录

#if UNITY_STANDALONE
    public static string osDir = "Win";
#elif UNITY_ANDROID
    public static string osDir = "luaframework";//查看手机 luaframework 文件路径是在 luaframework  不是 Android,
#elif UNITY_IPHONE
    public static string osDir = "iOS";        
#else
    public static string osDir = "";        
#endif

    public static string luaResDir = string.Format("{0}/{1}/Lua", Application.persistentDataPath, osDir);      //手机运行时lua文件下载目录    
    .
    .
    .
}

解决方案:

修改正确路径LuaConst.cs 修改如上LuaFileUtils.cs。里面有个函数AddSearchPath在LuaState.cs 中有个函数(AddSearchPath)调用,这里也要修改正正确的路径

public void AddSearchPath(string fullPath)
        {
            if (!Path.IsPathRooted(fullPath))
            {
                throw new LuaException(fullPath + " is not a full path");
            }

           
            RuntimePlatform  plat= Application.platform;
            switch (plat)
            {
                case RuntimePlatform.Android:
                    fullPath = Application.persistentDataPath+ "/luaframework/lua/?.lua";

                    break;
                default:
                    fullPath = ToPackagePath(fullPath);
                   
                    break;
            }
            LuaFileUtils.Instance.AddSearchPath(fullPath);        
        }

搜寻到的解决方案:

安卓上面报错LuaException: cannot open tolua.lua:
感谢!

 类似资料:

相关阅读

相关文章

相关问答