Lua是一种嵌入式语言,在C中通过Lua库来执行,Lua和C的通信要通过一个虚拟栈。
C的API:
操作栈函数
1 /*压入栈函数 lua_psuhtype*/ 2 void lua_pushnil (lua_State *L); 3 void lua_pushboolean (lua_State *L, int bool); 4 void lua_pushnumber (lua_State *L, lua_Number n); 5 void lua_pushinteger (lua_State *L, lua_Integer n); 6 void lua_pushunsigned (lua_State *L, lua_Unsigned n); 7 void lua_pushlstring (lua_State *L, const char *s, size_t len); 8 void lua_pushstring (lua_State *L, const char *s); 9 /*检测栈空间*/ 10 int lua_checkstack (lua_State *L, int sz);
查询栈函数
/*检测栈元素能否转化为对应类型*/ int lua_is* (lua_State *L, int index); /*返回栈元素类型*/ int lua_type (lua_State *L, int index); /*返回栈元素对应值*/ int lua_toboolean (lua_State *L, int index); const char *lua_tolstring (lua_State *L, int index, size_t *len); lua_Number lua_tonumber (lua_State *L, int index); lua_Integer lua_tointeger (lua_State *L, int index); lua_Unsigned lua_tounsigned (lua_State *L, int idx);
时间: 2024-10-08 11:13:20