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()

Lua判断OS并添加cpath的更多相关文章

  1. lua判断字符串包含另一个字符串

    lua判断字符串包含另一个字符串 --string.find("元字符串","模式字符串") 如下: print(string.find("CCBWe ...

  2. 判断页面是否添加了W3C声明

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. jq select change下拉框选项变化判断选中值,添加(attr)或移除(removeAttr)一个或多个属性

    select change下拉框选项变化判断选中值,添加(attr)或移除(removeAttr)一个或多个属性 $("#IsRecommend").change(function ...

  4. Cent OS 7 添加 EPEL Nux Dextop ELRepo等源

    Cent OS 7 添加第三方yum源 CentOS由于很追求稳定性,所以官方源中自带的软件不多,因而需要一些第三方源. 比如EPEL.ATrpms.ELRepo.Nux Dextop.RepoFor ...

  5. lua判断表中数据是否连续,0可以代表任何数

    最近看到有lua面试题,挺有意思的,一张表中有若干个数,0可以代表任何数 比如有张表{9, 2, 4, 1, 3, 0, 0, 0, 0},按照规则这张表中的四个0可以用来代表5,6,7,8,那么这张 ...

  6. x01.os.16: 添加功能

    准备工作  1.确保是 win xp,如是 win 8,运行 nasm 需按提示同意安装组件.  2.确保 src 和 z_tools 在同一目录下,nasm 已包含在 z_tools 文件夹中.  ...

  7. Lua 判断文件类型为wav

    [1]应用示例 文件类型为wav格式 -- 判断文件类型 local function isType(filename) local res = string.match(filename, &quo ...

  8. Lua 判断表是否为空方法

    [1]判断表为空的方法 目前为止,Lua语言中判断table表是否为空有三种方式: (1)#table,当table为数组时直接返回table表的长度. (2)当table是字典时,返回table的长 ...

  9. lua -- 在面板中添加多个部件

    function UIBagController:initItemView( ) -- 获取面板 self.panelCenter = tolua.cast(UIHelper:seekWidgetBy ...

随机推荐

  1. iframe交互(一)父页面自动高度

    //父页面源码 <body style="border:1px solid red;width:200px;height:500px;" onload="IFram ...

  2. JavaScript数据结构与算法(三) 优先级队列的实现

    TypeScript方式实现源码 // Queue类和PriorityQueue类实现上的区别是,要向PriorityQueue添加元素,需要创建一个特殊的元素.这个元素包含了要添加到队列的元素(它可 ...

  3. [LeetCode] Lonely Pixel II 孤独的像素之二

    Given a picture consisting of black and white pixels, and a positive integer N, find the number of b ...

  4. [LeetCode] Increasing Subsequences 递增子序列

    Given an integer array, your task is to find all the different possible increasing subsequences of t ...

  5. Python系列之 - 面向对象(2)

    类的三大特性 类的三大特性包括: 封装.继承.多态 一 封装 封装就是将类所用到的所有字段.属性.方法都包含在类代码段里面,当实例调用直接调用类中的方法即可. class People(object) ...

  6. pytorch 移动端框架 thnets 附c示例代码

    前年年前做一个手机移动端图像识别项目的时候, 先后尝试了mxnet,thnets,caffe,tensorflow. 当时的情况是,mxnet内存管理奇差,内存经常由于模型运算分配不足,app挂掉. ...

  7. [ZJOI2016]小星星

    题目描述 小Y是一个心灵手巧的女孩子,她喜欢手工制作一些小饰品.她有n颗小星星,用m条彩色的细线串了起来,每条细线连着两颗小星星. 有一天她发现,她的饰品被破坏了,很多细线都被拆掉了.这个饰品只剩下了 ...

  8. hdu5652 India and China Origins(并查集)

    India and China Origins  Accepts: 49  Submissions: 426  Time Limit: 2000/2000 MS (Java/Others)  Memo ...

  9. [BZOJ]1050 旅行comf(HAOI2006)

    图论一直是小C的弱项,相比其它题型,图论的花样通常会更多一点,套路也更难捉摸. Description 给你一个无向图,N(N<=500)个顶点, M(M<=5000)条边,每条边有一个权 ...

  10. bzoj3786星系探索 splay

    3786: 星系探索 Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 1314  Solved: 425[Submit][Status][Discuss ...