IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Lua判断OS并添加cpath

    金庆发表于 2016-06-20 12:19:00
    love 0
    Lua判断OS并添加cpath

    (金庆的专栏)

    Lua初始化时需要根据OS来设置package.cpath,
    如果是Windows系统则添加 ?.dll, 否则添加 ?.so.
    不然加载错误后缀名的动态库会报错。

    local function add_package_cpath(subDir)
        if is_windows then
            package.cpath = package.cpath..";"..G_LUA_ROOTPATH.."/"..subDir.."/?.dll"
        else
            package.cpath = package.cpath..";"..G_LUA_ROOTPATH.."/"..subDir.."/?.so"
        end
    end

    Lua没有提供OS判断功能,所以利用 package.config 中的目录分隔符来判断。

    -- return true if os is windows
    local function get_is_windows()
        return "\\" == package.config:sub(1,1)
    end

    local is_windows = get_is_windows()


    金庆 2016-06-20 20:19 发表评论


沪ICP备19023445号-2号
友情链接