- 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 (...)
lua_Alloc
typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
The type of the memory-allocation function used by Lua states. The allocator function must provide a functionality similar to realloc
, but not exactly the same. Its arguments are ud
, an opaque pointer passed to lua_newstate
; ptr
, a pointer to the block being allocated/reallocated/freed; osize
, the original size of the block; nsize
, the new size of the block. ptr
is NULL
if and only if osize
is zero. When nsize
is zero, the allocator must return NULL
; if osize
is not zero, it should free the block pointed to by ptr
. When nsize
is not zero, the allocator returns NULL
if and only if it cannot fill the request. When nsize
is not zero and osize
is zero, the allocator should behave like malloc
. When nsize
and osize
are not zero, the allocator behaves like realloc
. Lua assumes that the allocator never fails when osize >= nsize
.
Here is a simple implementation for the allocator function. It is used in the auxiliary library by lua_newstate
.
static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { (void)ud; /* not used */ (void)osize; /* not used */ if (nsize == 0) { free(ptr); /* ANSI requires that free(NULL) has no effect */ return NULL; } else /* ANSI requires that realloc(NULL, size) == malloc(size) */ return realloc(ptr, nsize); }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论