Lua的API函数
1. 基础库
我们在整个教程中使用了各种主题下的基本库。 下表提供了相关页面的链接,并列出了本Lua教程各部分所涵盖的功能。
|
编号 |
库/方法 |
作用 |
|
1 |
错误处理 |
包括错误处理函数,如断言, 错误,如Lua错误处理中所述。 |
|
2 |
内存管理 |
包括与垃圾收集相关的自动内存管理功能, 如Lua垃圾收集中所述。 |
|
3 |
|
它打开文件并以块的形式执行文件的内容。 |
|
4 |
|
因此是保存全局环境的全局变量(即 |
|
5 |
|
返回函数使用的当前环境。 |
|
6 |
|
如果 |
|
7 |
|
此函数获取表的索引和值。 |
|
8 |
|
使用函数 |
|
9 |
|
与 |
|
10 |
|
与 |
|
11 |
|
允许程序遍历表的所有字段。 |
|
12 |
|
暂停正在运行的协同程序。 |
|
13 |
|
打印给定的参数值。 |
|
14 |
|
检查 |
|
15 |
|
获取 |
|
16 |
|
将 |
|
17 |
|
如果 |
|
18 |
|
设置给定函数使用的环境。 |
|
19 |
|
设置给定表的元表。 |
|
20 |
|
尝试将参数转换为数字。 |
|
21 |
|
接收任何类型的参数并将其转换为合理格式的字符串。 |
|
22 |
|
返回唯一参数的类型,编码为字符串。 |
|
23 |
|
返回给定表中的元素。 |
|
24 |
|
包含当前解释器版本的字符串的全局变量(不是函数)。 |
|
25 |
协同程序 |
包括Lua协同程序中解释的协程操作功能。 |
2. Lua数学库
|
编号 |
库或方法 |
描述 |
|
1 |
|
返回 |
|
2 |
|
返回 |
|
3 |
|
返回 |
|
4 |
|
返回 |
|
5 |
|
返回 |
|
6 |
|
返回大于或等于 |
|
7 |
|
返回 |
|
8 |
|
返回 |
|
9 |
|
以度为单位返回角度 |
|
10 |
|
返回值 |
|
11 |
|
返回小于或等于 |
|
12 |
|
返回 |
|
13 |
|
返回 |
|
14 |
|
|
|
15 |
|
返回 |
|
16 |
|
返回 |
|
17 |
|
返回 |
|
18 |
|
返回参数中的最大值。 |
|
19 |
|
返回参数中的最小值。 |
|
20 |
|
返回两个数字, |
|
21 |
|
|
|
22 |
|
返回 |
|
23 |
|
以弧度为单位返回角度 |
|
24 |
|
此函数是ANSI C提供的简单伪随机生成器函数rand的接口。 |
|
25 |
|
将 |
|
26 |
|
返回 |
|
27 |
|
返回 |
|
28 |
|
返回 |
|
29 |
|
返回 |
|
30 |
|
返回 |
三角函数
使用三角函数的简单示例如下所示-
radianVal=math.rad(math.pi/2)
io.write(radianVal,"\n")
-- Sin value of 90(math.pi / 2) degrees
io.write(string.format("%.1f ",math.sin(radianVal)),"\n")
-- Cos value of 90(math.pi / 2) degrees
io.write(string.format("%.1f ",math.cos(radianVal)),"\n")
-- Tan value of 90(math.pi / 2) degrees
io.write(string.format("%.1f ",math.tan(radianVal)),"\n")
-- Cosh value of 90(math.pi / 2) degrees
io.write(string.format("%.1f ",math.cosh(radianVal)),"\n")
-- Pi Value in degrees
io.write(math.deg(math.pi),"\n")
当运行上面的程序时,将得到以下输出 -
0.0274155677808040.01.00.01.0180
其他常见的数学函数
使用常见数学函数的简单示例如下所示-
-- Floor
io.write("Floor of 10.5055 is ",math.floor(10.5055),"\n")
-- Ceil
io.write("Ceil of 10.5055 is ",math.ceil(10.5055),"\n")
-- Square root
io.write("Square root of 16 is ",math.sqrt(16),"\n")
-- Power
io.write("10 power 2 is ",math.pow(10,2),"\n")
io.write("100 power 0.5 is ",math.pow(100,0.5),"\n")
-- Absolute
io.write("Absolute value of -10 is ",math.abs(-10),"\n")
--Random
math.randomseed(os.time())
io.write("Random number between 1 and 100 is ",math.random(),"\n")
--Random between 1 to 100
io.write("Random number between 1 and 100 is ",math.random(1,100),"\n")
--Max
io.write("Maximum in the input array is ",math.max(1,100,101,99,999),"\n")
--Min
io.write("Minimum in the input array is ",math.min(1,100,101,99,999),"\n")
当运行上面的程序时,将得到以下输出 -
Floor of 10.5055 is 10
Ceil of 10.5055 is 11
Square root of 16 is 4
10 power 2 is 100
100 power 0.5 is 10
Absolute value of -10 is 10
Random number between 1 and 100 is 0.22876674703207
Random number between 1 and 100 is 7
Maximum in the input array is 999
Minimum in the input array is 1
3. Lua操作系统工具
|
编号 |
库或方法 |
描述 |
|
1 |
|
返回程序使用的CPU时间(以秒为单位)的近似值。 |
|
2 |
|
返回包含日期和时间的字符串或表,根据给定的字符串格式进行格式化。 |
|
3 |
|
返回从时间 |
|
4 |
|
此功能相当于ANSI C功能系统。 它传递要由操作系统shell执行的命令。 如果命令成功终止,则第一个结果为 |
|
5 |
|
调用ANSI C函数出口以终止宿主程序。 如果 |
|
6 |
|
返回进程环境变量 |
|
7 |
|
使用给定名称删除文件(或POSIX系统上的空目录)。 如果此函数失败,则返回 |
|
8 |
|
将名为 |
|
9 |
|
设置程序的当前区域设置。 |
|
10 |
|
返回不带参数调用的当前时间,或表示给定表指定的日期和时间的时间。 此表必须包含字段年,月和日,并且可能包含字段小时(默认值为 |
|
11 |
|
返回一个文件名,该文件名可用于临时文件。 文件必须在使用前显式打开,并在不再需要时显式删除。 |
常见的OS功能
使用常见数学函数的简单示例如下所示 -
-- Date with format
io.write("The date is ",os.date("%m/%d/%Y"),"\n")
-- Date and time
io.write("The date and time is ",os.date(),"\n")
-- Time
io.write("The OS time is ",os.time(),"\n")
-- Wait for some timefori=1,1000000doend
-- Time since Lua started
io.write("Lua started before ",os.clock(),"\n")
当运行上面的程序时,将得到类似的输出如下 -
The date is 01/25/2018
The date and time is 01/25/18 07:38:40
The OS time is 1490615720
Lua started before 0.013
上面的例子只是一些常见的例子,可根据自己的需要使用OS库,建议尝试使用所有的功能以便更加熟悉。像remove这样的函数有助于删除文件,执行有助于于执行OS命令。
--------------------------------------------------
转载于:https://www.yiibai.com/lua/lua_operating_system_facilities.html
Lua的API函数的更多相关文章
- lua API函数大全
Lua5.1中的API函数 lua_State* luaL_newstate()Lua脚本的编译执行是相互独立的,在不同的线程上执行.通过luaL_newstate()函数可以申请一个虚拟机,返回指针 ...
- VC和VS调用Lua设置以及Lua C API使用。
通过c++调用lua 脚本, 环境VC++6.0 lua sdk 5.1.4 在调用前先认识几个函数.1.调用lua_open()将创建一个指向Lua解释器的指针.2. luaL_ope ...
- Lua常用API
转自:http://www.cnblogs.com/ringofthec/archive/2010/10/22/lua.html 1. 建一个新表 void lua_createtable (lua ...
- Lua C API的正确用法
http://blog.codingnow.com/2015/05/lua_c_api.html http://blog.csdn.net/oilcode/article/details/510861 ...
- Windows API 函数列表 附帮助手册
所有Windows API函数列表,为了方便查询,也为了大家查找,所以整理一下贡献出来了. 帮助手册:700多个Windows API的函数手册 免费下载 API之网络函数 API之消息函数 API之 ...
- lua实现私有函数
本文是原创文章,如需转载,请注明文章出处 要用lua实现私有函数,关键就是使用metatable的特性来实现. Test.lua: local v = {};v.x = 100;v.y = 200; ...
- C#中可直接调用WIN32的API函数--USER32.DLL
Win32的API函数可以直接在C#中直接调用,在做WinForm时还是很有帮助的.有时候直接调用Win32的API,可以很高效的实现想要的效果. using System; using System ...
- Appium常用的API函数
在学习应用一个框架之前,应该了解一下这个框架的整体结构或是相应的API函数.这篇文章还不错:http://blog.sina.com.cn/s/blog_68f262210102vzf9.html,就 ...
- mfc 调用Windows的API函数实现同步异步串口通信(源码)
在工业控制中,工控机(一般都基于Windows平台)经常需要与智能仪表通过串口进行通信.串口通信方便易行,应用广泛. 一般情况下,工控机和各智能仪表通过RS485总线进行通信.RS485的通信方式是半 ...
随机推荐
- 转载:在Excel中将数据库字段转换成驼峰式
转载地址 在Excel中将数据库字段转换成驼峰式 1.将数据库字段复制到Excel表格第一列: 2.在第二列顶部输入=PROPER(A1)命令: 3.在第三列顶部输入=SUBSTITUTE(B1,&q ...
- 微信小程序之scroll-view的坑
好久没动小程序了,今天打算复习复习,结果刚写了一个scroll-view就遇到了一个坑,这怎么能忍,对比看文档也没发现那里出了问题,没办法只能去翻翻微信给的demo,发现scroll-view一个必要 ...
- arcgis python desc.dataType
desc = arcpy.Describe(r"C:\Users\dell\Documents\ArcGIS\ddd.shp") 是ShapeFile desc = arcpy.D ...
- Download google drive public shared file in terminal
http://unix.stackexchange.com/questions/136371/how-to-download-a-folder-from-google-drive-using-term ...
- django-admin 配置
本节讲django-admin配置方法: 1.在工程配置文件中(settings.py)中启用admin组件.确保有如下两行配置: 2.执行数据库迁移的命令,确保对应的表在数据库中已经添加了 #pyt ...
- 性能测试 | 系统运行缓慢,CPU 100%,Full GC次数过多问题排查
处理过线上问题的同学基本上都会遇到系统突然运行缓慢,CPU 100%,以及Full GC次数过多的问题.当然,这些问题的最终导致的直观现象就是系统运行缓慢,并且有大量的报警.本文主要针对系统运行缓慢这 ...
- JavaScript中原型链存在的问题解析
我们知道使用原型链实现继承是一个goodway:)看个原型链继承的例子. function A () { this.abc = 44; } A.prototype.getAbc = function ...
- pm2 使用
详见:https://www.cnblogs.com/chyingp/p/pm2-documentation.html
- JAVA 基础编程练习题16 【程序 16 输入 9*9 表】
16 [程序 16 输入 9*9 表] 题目:输出 9*9 口诀. 程序分析:分行与列考虑,共 9 行 9 列,i 控制行,j 控制列. package cskaoyan; public class ...
- Servlet(2):Requset/Response Encoding and Filter
Requset/Response Encoding 表单提交分GET和POST,接下来分开讨论. (1)GET/URL提交的数据 在 Tomcat中,默认情况下使用"URIEncoding& ...