- 1 - 介绍
- 2.1 - 语法约定
- 2.10.1 - 垃圾收集的元方法
- 2.10.2 - Weak Table(弱表)
- 2.10 - 垃圾收集
- 2.11 - Coroutine (协同例程)
- 2.2.1 - 强制转换
- 2.2 - 值与类型
- 2.3 - 变量
- 2.4.1 - Chunk(语句组)
- 2.4.2 - 语句块
- 2.4.3 - 赋值
- 2.4.4 - 控制结构
- 2.4.5 - For 语句
- 2.4.6 - 把函数调用作为语句段
- 2.4.7 - 局部变量声名
- 2.4 - 语句段(Statement)
- 2.5.1 - 数学运算操作符
- 2.5.2 - 比较操作符
- 2.5.3 - 逻辑操作符
- 2.5.4 - 连接符
- 2.5.5 - 取长度操作符
- 2.5.6 - 优先级
- 2.5.7 - Table 构造
- 2.5.8 - 函数调用
- 2.5.9 - 函数定义
- 2.5 - 表达式
- 2.6 - 可视规则
- 2.7 - 错误处理
- 2.8 - Metatable(元表)
- 2.9 - 环境
- 2 - 语言
- 3.1 - 堆栈
- 3.2 - 堆栈尺寸
- 3.3 - 伪索引
- 3.4 - C Closure
- 3.5 - 注册表
- 3.6 - C 中的错误处理
- 3.7 - 函数和类型
- 3.8 - 调试接口
- 3 - 程序接口(API)
- 4.1 - Functions and Types
- 4 - The Auxiliary Library
- 5.1 - Basic Functions
- 5.2 - Coroutine Manipulation
- 5.3 - Modules
- 5.4 - String Manipulation
- 5.5 - Table Manipulation
- 5.6 - Mathematical Functions
- 5.7 - Input and Output Facilities
- 5.8 - Operating System Facilities
- 5.9 - The Debug Library
- 5 - Standard Libraries
- 6 - Lua Stand-alone
- 7.1 - Changes in the Language
- 7.2 - Changes in the Libraries
- 7.3 - Changes in the API
- 7 - Incompatibilities with the Previous Version
- 8 - The Complete Syntax of Lua
- Captures
- Character Class:
- luaL_addchar
- luaL_addlstring
- luaL_addsize
- luaL_addstring
- luaL_addvalue
- luaL_argcheck
- luaL_argerror
- luaL_Buffer
- luaL_buffinit
- luaL_callmeta
- luaL_checkany
- luaL_checkint
- luaL_checkinteger
- luaL_checklong
- luaL_checklstring
- luaL_checknumber
- luaL_checkoption
- luaL_checkstack
- luaL_checkstring
- luaL_checktype
- luaL_checkudata
- luaL_dofile
- luaL_dostring
- luaL_error
- luaL_getmetafield
- luaL_getmetatable
- luaL_gsub
- luaL_loadbuffer
- luaL_loadfile
- luaL_loadstring
- luaL_newmetatable
- luaL_newstate
- luaL_openlibs
- luaL_optint
- luaL_optinteger
- luaL_optlong
- luaL_optlstring
- luaL_optnumber
- luaL_optstring
- luaL_prepbuffer
- luaL_pushresult
- luaL_ref
- luaL_Reg
- luaL_register
- luaL_typename
- luaL_typerror
- luaL_unref
- luaL_where
- lua_Alloc
- lua_atpanic
- lua_call
- lua_CFunction
- lua_checkstack
- lua_close
- lua_concat
- lua_cpcall
- lua_createtable
- lua_Debug
- lua_dump
- lua_equal
- lua_error
- lua_gc
- lua_getallocf
- lua_getfenv
- lua_getfield
- lua_getglobal
- lua_gethook
- lua_gethookcount
- lua_gethookmask
- lua_getinfo
- lua_getlocal
- lua_getmetatable
- lua_getstack
- lua_gettable
- lua_gettop
- lua_getupvalue
- lua_Hook
- lua_insert
- lua_Integer
- lua_isboolean
- lua_iscfunction
- lua_isfunction
- lua_islightuserdata
- lua_isnil
- lua_isnumber
- lua_isstring
- lua_istable
- lua_isthread
- lua_isuserdata
- lua_lessthan
- lua_load
- lua_newstate
- lua_newtable
- lua_newthread
- lua_newuserdata
- lua_next
- lua_Number
- lua_objlen
- lua_pcall
- lua_pop
- lua_pushboolean
- lua_pushcclosure
- lua_pushcfunction
- lua_pushfstring
- lua_pushinteger
- lua_pushlightuserdata
- lua_pushlstring
- lua_pushnil
- lua_pushnumber
- lua_pushstring
- lua_pushthread
- lua_pushvalue
- lua_pushvfstring
- lua_rawequal
- lua_rawget
- lua_rawgeti
- lua_rawset
- lua_rawseti
- lua_Reader
- lua_register
- lua_remove
- lua_replace
- lua_resume
- lua_setallocf
- lua_setfenv
- lua_setfield
- lua_setglobal
- lua_sethook
- lua_setlocal
- lua_setmetatable
- lua_settable
- lua_settop
- lua_setupvalue
- lua_State
- lua_status
- lua_toboolean
- lua_tocfunction
- lua_tointeger
- lua_tolstring
- lua_tonumber
- lua_topointer
- lua_tostring
- lua_tothread
- lua_touserdata
- lua_type
- lua_typename
- lua_Writer
- lua_xmove
- lua_yield
- Pattern:
- Pattern Item:
- assert (v [, message])
- collectgarbage (opt [, arg])
- coroutine.create (f)
- coroutine.resume (co [, val1, ···])
- coroutine.running ()
- coroutine.status (co)
- coroutine.wrap (f)
- coroutine.yield (···)
- debug.debug ()
- debug.getfenv (o)
- debug.gethook ([thread])
- debug.getinfo ([thread,] function [, what])
- debug.getlocal ([thread,] level, local)
- debug.getmetatable (object)
- debug.getregistry ()
- debug.getupvalue (func, up)
- debug.setfenv (object, table)
- debug.sethook ([thread,] hook, mask [, count])
- debug.setlocal ([thread,] level, local, value)
- debug.setmetatable (object, table)
- debug.setupvalue (func, up, value)
- debug.traceback ([thread,] [message])
- dofile (filename)
- error (message [, level])
- getfenv (f)
- getmetatable (object)
- io.close ([file])
- io.flush ()
- io.input ([file])
- io.lines ([filename])
- io.open (filename [, mode])
- io.output ([file])
- io.popen ([prog [, mode]])
- io.read (···)
- io.tmpfile ()
- io.type (obj)
- io.write (···)
- ipairs (t)
- load (func [, chunkname])
- loadfile ([filename])
- loadstring (string [, chunkname])
- math.abs (x)
- math.acos (x)
- math.asin (x)
- math.atan (x)
- math.atan2 (x, y)
- math.ceil (x)
- math.cos (x)
- math.cosh (x)
- math.deg (x)
- math.exp (x)
- math.floor (x)
- math.fmod (x, y)
- math.frexp (x)
- math.huge
- math.ldexp (m, e)
- math.log (x)
- math.log10 (x)
- math.max (x, ···)
- math.min (x, ···)
- math.modf (x)
- math.pi
- math.pow (x, y)
- math.rad (x)
- math.random ([m [, n]])
- math.randomseed (x)
- math.sin (x)
- math.sinh (x)
- math.sqrt (x)
- math.tan (x)
- math.tanh (x)
- module (name [, ···])
- next (table [, index])
- os.clock ()
- os.date ([format [, time]])
- os.difftime (t2, t1)
- os.execute ([command])
- os.exit ([code])
- os.getenv (varname)
- os.remove (filename)
- os.rename (oldname, newname)
- os.setlocale (locale [, category])
- os.time ([table])
- os.tmpname ()
- package.cpath
- package.loaded
- package.loadlib (libname, funcname)
- package.path
- package.preload
- package.seeall (module)
- pairs (t)
- pcall (f, arg1, ···)
- print (···)
- rawequal (v1, v2)
- rawget (table, index)
- rawset (table, index, value)
- require (modname)
- select (index, ···)
- setfenv (f, table)
- setmetatable (table, metatable)
- string.byte (s [, i [, j]])
- string.char (···)
- string.dump (function)
- string.find (s, pattern [, init [, plain]])
- string.format (formatstring, ···)
- string.gmatch (s, pattern)
- string.gsub (s, pattern, repl [, n])
- string.len (s)
- string.lower (s)
- string.match (s, pattern [, init])
- string.rep (s, n)
- string.reverse (s)
- string.sub (s, i [, j])
- string.upper (s)
- table.concat (table [, sep [, i [, j]]])
- table.insert (table, [pos,] value)
- table.maxn (table)
- table.remove (table [, pos])
- table.sort (table [, comp])
- tonumber (e [, base])
- tostring (e)
- type (v)
- unpack (list [, i [, j]])
- xpcall (f, err)
- _G
- _VERSION
- file:close ()
- file:flush ()
- file:lines ()
- file:read (...)
- file:seek ([whence] [, offset])
- file:setvbuf (mode [, size])
- file:write (...)
require (modname)
Loads the given module.
The function starts by looking into the table package.loaded
to determine whether modname
is already loaded.
If it is, then require
returns the value stored
at package.loaded[modname]
.
Otherwise, it tries to find a loader for the module.
To find a loader,
first require
queries package.preload[modname]
.
If it has a value,
this value (which should be a function) is the loader.
Otherwise require
searches for a Lua loader using the
path stored in package.path
.
If that also fails, it searches for a C loader using the
path stored in package.cpath
.
If that also fails,
it tries an all-in-one loader (see below).
When loading a C library,require
first uses a dynamic link facility to link the
application with the library.
Then it tries to find a C function inside this library to
be used as the loader.
The name of this C function is the string "luaopen_
"
concatenated with a copy of the module name where each dot
is replaced by an underscore.
Moreover, if the module name has a hyphen,
its prefix up to (and including) the first hyphen is removed.
For instance, if the module name is a.v1-b.c
,
the function name will be luaopen_b_c
.
If require
finds neither a Lua library nor a
C library for a module,
it calls the all-in-one loader.
This loader searches the C path for a library for
the root name of the given module.
For instance, when requiring a.b.c
,
it will search for a C library for a
.
If found, it looks into it for an open function for
the submodule;
in our example, that would be luaopen_a_b_c
.
With this facility, a package can pack several C submodules
into one single library,
with each submodule keeping its original open function.
Once a loader is found,require
calls the loader with a single argument, modname
.
If the loader returns any value,require
assigns it to package.loaded[modname]
.
If the loader returns no value and
has not assigned any value to package.loaded[modname]
,
then require
assigns true to this entry.
In any case, require
returns the
final value of package.loaded[modname]
.
If there is any error loading or running the module,
or if it cannot find any loader for the module,
then require
signals an error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论