• lua基础之Base


    _G

    变量是全局环境表。 (_G._G == _G)
    您不能通过分配给 _G 来更改环境,而是使用 setfenv。

    _VERSION

    一个全局变量,它是一个包含当前 Lua 解释器版本的字符串。

    print (_VERSION) --> Lua 5.1

    v = assert (v, message)

    Asserts that condition is not nil and not false

    collectgarbage (opt, arg)

    • “stop”:停止垃圾收集器。
    • “restart”:重启垃圾收集器。
    • “collect”:执行完整的垃圾收集周期(如果没有提供选项,这是默认设置)
    • “count”:返回 Lua 使用的总内存(以 KB 为单位)。
    • “step”:执行垃圾收集步骤。 步骤“大小”由 arg 以非指定方式控制(较大的值意味着更多的步骤)。 如果要控制步长,则必须通过实验调整 arg 的值。 如果该步骤完成了一个收集周期,则返回 true。
    • “setpause”:将 arg/100 设置为收集器暂停的新值(见下文)。
    • “setstepmul”:将 arg/100 设置为收集器步长乘数的新值(见下文)。

    Lua 实现了一个增量标记清除收集器。它使用两个数字来控制其垃圾收集周期:垃圾收集器暂停和垃圾收集器步骤乘数。

    垃圾收集器暂停控制收集器在开始新循环之前等待的时间。较大的值使收集器不那么激进。小于 1 的值意味着收集器不会等待开始新的循环。值为 2 意味着收集器在开始新循环之前等待使用中的总内存翻倍。

    step multiplier 控制收集器相对于内存分配的相对速度。较大的值使收集器更具侵略性,但也会增加每个增量步骤的大小。小于 1 的值会使收集器太慢,并可能导致收集器永远不会完成一个循环。默认值 2 表示收集器以内存分配速度的“两倍”运行。

    “setpause”和“setstepmul”都将百分比作为参数(因此参数 100 意味着实际值为 1)。当 Lua 启动时,两者都默认为 200(因为它们除以 100,实际上默认值为 2,如上所述)。

    collectgarbage (“collect”) --> forces garbage collection

    val = dofile (filename)

    打开命名文件,将其内容作为 Lua 块进行解析和执行。
    如果发生错误则引发错误。 返回块返回的任何值。

    dofile ("myfile.lua") 
    
    function dofile (filename)
      local f = assert (loadfile (filename))
      return f ()
    end -- dofile
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    error (message, level)

    使用提供的消息引发错误。 永远不会return。 如果提供了一个级别,则错误指向当前函数(级别 1 或 nil)、父函数(级别 2)等。

    t = getfenv (f)

    返回指定函数 f 使用的当前环境。
    f 可以是一个函数或一个代表堆栈级别的数字,其中 1 是当前正在运行的函数,2 是它的父函数,依此类推。

    环境是存储“全局”变量的地方。

    print (getfenv (1)) --> table: 02072780
    print (_G) --> table: 02072780

    getmetatable

    Returns the metatable for the object

    ipairs

    Iterates over a numerically keyed table

    load

    Loads a chunk by calling a function repeatedly

    loadfile

    Loads a Lua file and parses it

    loadstring

    Compiles a string of Lua code

    module

    Creates a Lua module

    next

    Returns next key / value pair in a table

    pairs

    Traverse all items in a table

    pcall

    Calls a function in protected mode

    print

    Prints its arguments

    rawequal

    Compares two values for equality without invoking## metamethods

    rawget

    Gets the value of a table item without invoking## metamethods

    rawset

    Sets the value of a table item without invoking## metamethods

    require

    Loads a module

    select

    Returns items in a list

    setfenv

    Sets a function’s environment

    setmetatable

    Sets the metatable for a table

    tonumber

    Converts a string (of the given base) to a number

    tostring

    Converts its argument to a string

    type

    Returns the type of a variable

    unpack

    Unpacks a table into individual items

    xpcall

    Calls a function with a custom error handler

  • 相关阅读:
    解决iOS Retina屏幕0.5pt线宽颜色失真问题
    直播平台Stacked完成1290万美元A轮融资,计划转型为Web3流媒体
    sketch设计不得不知道的五个高级功能
    使用SpringBatch读取csv文件
    含文档+PPT+源码等]精品微信小程序健康食谱系统微信小程序+后台管理系统|前后分离VUE[包运行成功]程序设计源码计算机毕设
    模具生产应用追溯RFID智能管理系统
    多线程之ConcurrentHashMap原理
    python安装第三方包的几种方式
    TCP服务器使用多路复用
    web前端期末大作业——网页制作基础大二dw作业——动画漫展学习资料电影模板(6页)
  • 原文地址:https://blog.csdn.net/a_codecat/article/details/127951936