lua_pushstring 减少内存拷贝 一、前言 本篇文章是小编对lua的一个终结篇,lua本身要学的并不是很多,很多都是三方模块,因此这里小编只能和大家最后再补充下lua的一些没讲到的地方。 二、垃圾收集器 lua提供了垃圾收集的功能,我们可以通过一个方法来实现,他就是collectgarbage,它里面有两个参数,分别为选项和参数,如下...
function newStack () return {""} -- starts with an empty string end function addString (stack, s) table.insert(stack, s) -- push 's' into the the stack for i=table.getn(stack)-1, 1, -1 do if string.len(stack[i]) > string.len(stack[i+1]) then break end stack[i] = sta...
lua_pushnumber void lua_pushnumber (lua_State *L, lua_Number n); 把一个数字n压栈。 lua_pushstring void lua_pushstring (lua_State *L, const char *s); 把指针s指向的以零结尾的字符串压栈。 Lua 对这个字符串做一次内存拷贝(或是复用一个拷贝),因此s处的内存在函数返回后,可以释放掉或是重...
lua_pushstring(L, "name"); //lua_gettable会在栈顶取出一个元素并且返回把查找到的值压入栈顶 lua_gettable(L, 1); */ lua_getfield(L,-1,"name");//lua_getfield(L,-1,"name")的作用等价于 lua_pushstring(L,"name") + lua_gettable(L,1) constchar*name = lua_tostring(L,-1);//在...
lua_pushstring(lua_State* L, const char* s) 说明:将一个 C 字符串(以空字符结尾的字符串)压入堆栈。 参数: L:Lua 状态(Lua 虚拟机实例)的指针。 s:要压入堆栈的 C 字符串。 最佳实践:使用该函数将 C 字符串压入堆栈,可以供 Lua 脚本使用。
lua c 常用 api 说明和注意事项 目录 收起 Lua 状态管理函数: lua_newstate lua_close lua_open 栈操作函数 lua_pushxxx,其中 xxx 代表不同的数据类型,如 lua_pushnumber、lua_pushstring 等。这些函数用于将不
lua_pushliteral# [-0, +1, e] const char *lua_pushliteral (lua_State *L, const char *s); 这个宏等价于 lua_pushstring, 区别仅在于只能在 s 是一个字面量时才能用它。 它会自动给出字符串的长度。 lua_pushlstring# [-0, +1, e] const char *lua_pushlstring (lua_State *L, const ch...
lua_ucl_to_string (lua_State *L, const ucl_object_t *obj, enum ucl_emitter type) { unsigned char *result; size_t len; result = ucl_object_emit (obj, type); result = ucl_object_emit_len (obj, type, &len); if (result != NULL) { lua_pushstring (L, (const char *)result)...
// cpp void lua_pushnil(lua_State *L); void lua_pushboolean(lua_State *L, int bool); void lua_pushnumber(lua_State *L, lua_Number n); void lua_pushinteger(lua_State *L, lua_Integer n); void lua_pushlstring(lua_State *L, const char* s, size_t len); void lua_pushstring(lu...
Lua中的数值默认是double类型的,要压入整数的时候用lua_pushinteger Lua的string不是0字符结尾的,它可以包含任意二进制数据 交互栈至少有20个槽位,这定义在lua.h中的LUA_MINSTACK 检查栈的槽位是否够用: int lua_checkstack (lua_State *L, int sz); ...