源码的前置知识
-
-
-
- 1 lua.h内的方法 lua和C交互的API
-
- 1.1 lua_register
- 1.2 lua_gettop
- 1.3 lua_pop
- 1.4 lua_tolstring
- 1.5 lua_tostring
- 1.6 lua_getfield
- 1.7 luaL_getmetatable
- 1.8 luaL_newmetatable
- 1.9 lua_getmetatable
- 1.10 lua_pushstring
- 1.11 lua_settable
- 1.12 lua_rawset
- 1.13 lua_gettable
- 1.14 lua_rawget
- 1.15 lua_pushinteger
- 1.16 lua_pushlightuserdata
- 1.17 lua_pushcclosure
- 1.18 lua_pushvalue
- 1.19 lua_setmetatable
- 1.20 lua_getglobal
- 1.21 lua_setglobal
- 1.22 lua_pushnil
- 1.23 lua_upvalueindex
- 1.24 lua_touserdata
- 1.25 lua_newtable
- 1.26 lua_createtable
- 1.27 lua_next
- 1.28 lua_tolstring
- 1.29 lua_tostring
- 1.30 lua_newuserdata
- 2 lua中的全局方法
- 3 Lua C++ 调用机制
-
-
1 lua.h内的方法 lua和C交互的API
1.1 lua_register
void lua_register (lua_State *L,
const char *name,
lua_CFunction f);
将C函数f设置为全局名称name的新值,
lua端可以通过name调用C方法f
1.2 lua_gettop
int lua_gettop (lua_State *L);
返回虚拟栈的顶部元素的索引,因为虚拟栈底是1,所以返回的是栈的大小
1.3 lua_pop
void lua_pop (lua_State *L, int n);
弹出n个值
1.4 lua_tolstring
const char *lua_tolstring (lua_State *L, int index, size_t *len);
栈index位置的值value转成C string , len不为空的时候,设置len为string的长度,value必须为string或者number,否则返回null。(不要在遍历的时候对key使用此方法)
返回对齐指针,指向虚拟机内的string,有终止符\0,但是可以包括其他0