• lua基础知识(基于RUNOOB总结)


    数据类型

    nil:无效值,相当于false

    boolean:

    number:(双精度浮点)

    string:字符串,单引号间的一串字符,双引号间的一串字符,[[ 与 ]] 间的一串字符。

    userdata:自定义类型

    function(自定义类型)

    thread :独立线程

    table:键值对,相当于字典,和数组的区别在与索引可以不是数字

    table.concat (table , 两字符串间的连接字符, start , end):连接字符串的函数

    table.insert (table, [pos,] value):在索引位置插入元素,不指定索引在末尾添加

    table.remove (table [, pos]):删除指定索引的元素,不指定索引在末尾添加

    table.sort (table [, comp]):对table排序

    变量

    print

    循环

    print

    流程控制

    print

    函数

    print

    运算符

    print

    字符串

    string.upper(argument):全部变成大写

    string.lower(argument):全部变成小写

    string.gsub(String,a,b,num)把a替换成b,num为替换次数,不填就是全部替换

    string.find(String,a,num)查找sting中的a字符串的位置,从num索引开始查找

    string.reverse(string)翻转string

    string.format(),返回一个类似print格式类似的字符串string.format("the value is:%d",4)-->the value is:4

    string.char(arg) 和 string.byte(arg[,int]),char和num的转化

    string.len(arg),计算字符串的长度,也可以用#字符串

    string.rep(string, n)返回字符串的n个拷贝

    ..:链接字符串

    string.gmatch(str, pattern):查找str中的pattern字符串

    string.match(str, pattern, init):返回str中的patern字符串,从init位置开始搜索

    数组

    见table,这里要注意数组的是从1索引开始的

    迭代器

    print

    print

    模块和包

    print

    元素

    print

    协同程序

    coroutine.create()     创建 coroutine,返回 coroutine, 传入参数是函数

    coroutine.resume()   重启 coroutine,和 create 配合使用返回值[ture/false,val1,val2...]

    coroutine.status()           查看 coroutine 的状态,返回状态:dead,suspended,running

    coroutine.wrap()       创建 coroutine,返回一个函数,直接调用,和 create 功能重复但有区别。

    coroutine.running()        返回正在跑的 coroutine,返回线程号,返回值[主ture/非主false]

    coroutine.yield()             挂起 coroutine,为suspended态这个和 resume 配合使用,可返回值。

    文件IO

    print

    错误处理

    print

    调试

    print

    垃圾回收

    print

    面向对象

    print

    数据库访问

    print

     

  • 相关阅读:
    FAQ: c++ 函数名后添加 const void function1(int &id) const
    FAQ: C++中定义类的对象:用new和不用new有何区别?
    How to create a project with existing folder of files in Visual Studio?
    How to export a template in Visual Studio?
    t4 multiple output sample
    fastjson1.2.48以下版本存在重大漏洞
    一秒完成springboot与logback配置
    统计greenplum_postgresql数据占用存储情况
    上传文件不落地转Base64字符串
    三个标签完成springboot定时任务配置
  • 原文地址:https://www.cnblogs.com/still-smile/p/13059974.html
Copyright © 2020-2023  润新知