`

lua5.2文档

    博客分类:
  • lua
 
阅读更多
模块管理:
The package library provides basic facilities for loading modules in Lua. It exports one function directly in the global environment: require. Everything else is exported in a table package.

require (modname)
require returns the value stored at package.loaded[modname]. Otherwise, it tries to find a loader for the module.


module (name [, ···])
Creates a module. If there is a table in package.loaded[name], this table is the module.Otherwise creates a new table t and sets it as the value of the global name and the value of package.loaded[name].
This function also initializes t._NAME with the given name,

Finally, module sets t as the new environment of the current function and the new value of package.loaded[name], so that require returns t.

package.seeall (module)
Sets a metatable for module with its __index field referring to the global environment, so that this module inherits values from the global environment. To be used as an option to function module.

摘自:http://blog.163.com/hbu_lijian/blog/static/126129153201422902256778/
1.dofile与loadfile
dofile当作Lua运行代码的chunk的一种原始的操作。dofile实际上是一个辅助的函数。真正完成功能的函数是loadfile;与dofile不同的是loadfile编译代码成中间码并且返回编译后的chunk作为一个函数,而不执行代码;另外loadfile不会抛出错误信息而是返回错误代。我们可以这样定义dofile:
function dofile (filename)
    local f = assert(loadfile(filename))
    return f()
end

如果loadfile失败assert会抛出错误。loadfile更加灵活。在发生错误的情况下,loadfile返回nil和错误信息,这样我们就可以自定义错误处理。另外,如果我们运行一个文件多次的话,loadfile只需要编译一次,但可多次运行。dofile却每次都要编译。

loadstring (string [, chunkname])
Similar to load, but gets the chunk from the given string.
To load and run a given string, use the idiom
     assert(loadstring(s))()
When absent, chunkname defaults to the given string.


Lua5.2:部分变化:
Function module is deprecated. It is easy to set up a module with regular Lua code.
Functions setfenv and getfenv were removed, because of the changes in environments.
增加 bit32模块
分享到:
评论

相关推荐

    LUA 5.1 5.2 5.3 中文文档中文手册

    lua 5.1 - 5.3 中文文档, word 格式, 压缩包中包含文件: Lua程序设计(jb51.net).chm lua5.2中文参考手册.doc lua-5.1中文手册(1).chm lua-5.1函数说明中文手册.chm Lua 5.1 参考手册.docx Lua 5.3 参考手册.docx

    luasdl2:Lua 5.1,Lua 5.2和LuaJIT的SDL 2.0的纯C绑定

    Lua-SDL2是SDL2与Lua 5.1,Lua 5.2,Lua 5.3,Lua 5.4和LuaJIT的纯C绑定。 当前版本是2.1,与SDL 2.0.1-2.0.5兼容。 Lua-SDL2在项目版本控制方面遵循标准。 特征 Lua-SDL2是SDL2的可移植绑定,以纯C语言编写以...

    lua5.2.2下载

    lua文档5.2.2官方文档,在这里下载。

    lua_run:在Android上编辑和运行Lua代码

    集成lua5.2离线文档 编译步骤 $ cd lua_run $ android update project -p . -t android-19 $ sh build_native.sh 使用luasocket库 拷贝jni/luasocket/src/*.lua 到/sdcard/.luaRun/目录下 测试luasocket local ...

    cartographer-melodic-devel.zip

    快速完成基于Ubuntu18.04的Cartographer以及Cartographer_ros安装脚本。 Cartographer由谷歌一直在维护,从之前的tf1到现在melodic版本上的tf2_ros都有更新...并且官方只更新代码,并没有对安装文档进行对应的更新,

    markdown:纯Lua中Markdown文本到HTML标记系统的实现

    markdown.lua 这是纯Lua中流行的文本标记语言Markdown的实现。... 除Lua 5.1之外,此版本已更新为可以在Lua 5.2和Lua 5.3下运行。 用法 local markdown = require " markdown " markdown (source) markd

    otouto:基于Lua的Telegram机器人,带有插件

    重要通知请现在使用。 该分支不再处于开发中,并且不会添加新功能... 如果您使用的是Lua 5.2,则还需要luautf8。 建议您将它们与Luarocks一起安装。 使用install-dependencies.sh脚本,可以在Ubuntu上轻松完成此操作。

    lua-http, 支持 HTTP(S) 1.0.1.1和 2.0的HTTP库;客户端和服务器.zip

    lua-http, 支持 HTTP(S) 1.0.1.1和 2.0的HTTP库;客户端和服务器 面向Lua的...特性异步异步( 包括DNS查找和 TLS )支持 HTTP(S) 版本 1.0,1.1和 2客户端和服务器的功能web sockets兼容 Lua 5.1.5.2.5.3和 LuaJIT 。文档

    shadowfiend:在线编程网站

    Popush 部署文档15 Sep 2013安装依赖软件版本Ubuntu Server13.04Nginx *1.5Node0.10MongoDB2.2GCC4.7GDB7.5Python2.7Perl5.14Ruby2.0Lua5.2JDK7.0*请下载源码编译,并以默认方式安装在 /usr/local/nginx获取源码git ...

    luchia:用于CouchDB的Lua API

    与Lua 5.1、5.2、5.3、5.4兼容100%单元测试覆盖率注意:1.x分支不再维护。 它与CouchDb 2.x和更早版本兼容。安装: 建议安装软件包管理器,因为通过此方法可以轻松安装所有必需和可选的依赖项。需要lua-cjson ...

    wxlua_tutorial:wxlua(围绕wxWidgets跨平台GUI库的lua脚本语言包装器)教程

    目录结构doc文件夹 --教程的主目录code文件夹 --代码集合包括wxlua自带例程还有本教程的例子src 文件夹 --wxlua的源码与lua5.1.4的源码,需要的自行看里面的文档编译bin 文件夹 --包含了编译好的wx库(win,linux...

    VerySimpleChunker:用Torch7编写的基于神经网络的分块器

    VerySimpleChunker关于VerySimpleChunker是高效的现成浅解析器。 经过CONLL-2000共享任务的培训,它达到了92%的准确性。...要解析此文档,只需运行以下命令: $th parse.lua sample.txt > output.txt

    LibPlay:理智的多媒体库

    Lua> = 5.2, 版权所有(C)2015-2018 PUC-Rio / Laboratorio TeleMidia 根据GNU自由文档许可版本1.3或自由软件基金会发布的任何更高版本,授予复制,分发和/或修改本文档的权限; 没有不变的部分,没有前封面...

    北京java笔试题-cpgf:cpgf库

    Lua(5.3、5.2 和 5.1)、Google V8 JavaScript、Python (2.7.3) 和 Mozilla SpiderMonkey JavaScript 绑定到 C++ 的脚本绑定引擎。 它基于反射库。 cpgf 回调——一个回调库,用于在 C++ 中实现信号/槽或回调。 它...

    开涛高可用高并发-亿级流量核心技术

    1.3.7 文档和注释 14 1.3.8 备份 14 1.4 总结 14 第2部分高可用 17 2 负载均衡与反向代理 18 2.1 upstream配置 20 2.2 负载均衡算法 21 2.3 失败重试 23 2.4 健康检查 24 2.4.1 TCP心跳检查 24 2.4.2 HTTP心跳检查 ...

    Cocos2D-X游戏开发技术精解

    1.6 技术文档 15 1.7 成功的游戏 17 1.8 Cocos2D-X引擎的体系 18 1.9 Cocos2D-X引擎的版权声明 19 1.10 本章小结 20 第2章 Cocos2D-X引擎的 开发环境 21 2.1 跨平台的开发 21 2.2 建立开发环境 23 2.2.1 PC开发环境 ...

    像计算机科学家一样思考Python(第2版).pdf

    业余时,作为一个编程语言爱好者,对D、Kotlin、Lua、Clojure、Scala、Julia、Go等语言均有了解,但至今仍为Python独特的风格、简洁的设计而惊叹。 目录 · · · · · · 第1章 程序之道 1 1.1 什么是程序 1 ...

Global site tag (gtag.js) - Google Analytics