金庆的专栏

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  423 随笔 :: 0 文章 :: 454 评论 :: 0 Trackbacks
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()
posted on 2016-06-20 20:19 金庆 阅读(1507) 评论(0)  编辑 收藏 引用 所属分类: 9. 其它

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理