美文网首页
#Lua# Stack Manipulation

#Lua# Stack Manipulation

作者: KomalZheng | 来源:发表于2017-03-28 22:06 被阅读41次

Lua C API提供了操纵The Stack的函数:

获取The Stack元素个数:

int lua_gettop(lua_State *L);

将栈顶设置到某个index:

void lua_settop(lua_State *L, int index);

如果index小于The Stack中的元素个数,那么The Stack发生截断;
如果index对应的即是栈顶元素,那么不做任何操作;
如果index对应的元素不存在,那么,The Stack将设置栈顶到index对应除,并使用nil填充扩展的值;

将某个元素复制后,push到栈顶

void lua_pushvalue(lua_State *L, int index);

旋转操作(暂时未看源码,不知何用)

void lua_rotate(lua_State *L, int index, int n);

拷贝指定位置的元素值到目标位置

拷贝 fromidx 对应的值到 toidx位置,于是toidx位置的值便无法再被访问

void lua_copy (lua_State *L, int fromidx, int toidx);

宏定义

#define lua_insert(L,idx)   lua_rotate(L, (idx), 1)

#define lua_remove(L,idx)   (lua_rotate(L, (idx), -1), lua_pop(L, 1))

#define lua_replace(L,idx)  (lua_copy(L, -1, (idx)), lua_pop(L, 1))

平凡操作

以下的操作,将不发生任何变化

lua_settop(L, -1);
lua_insert(L, -1);
lua_copy(L, x, x);

相关文章

  • #Lua# Stack Manipulation

    Lua C API提供了操纵The Stack的函数: 获取The Stack元素个数: 将栈顶设置到某个inde...

  • Manipulation

    这两天工作比较忙,陪宝宝的时间不多,感觉他有点不高兴。晚上回家跟他互动的时候他开始拿玩具砸我,一开始是小的,然后是...

  • Bit Manipulation

    Wiki Bit manipulation is the act of algorithmically manip...

  • Bit manipulation

    Bit manipulation is the act of algorithmically manipulati...

  • The "Science" of Manipulation

    尝试影响他人的思想和行为,毫无疑问和时间一样古老,但操纵到二十世纪初都没能成为一种科学,直到当巴普洛夫,一位俄国心...

  • bit manipulation

    Counting Bits [method1] naive O(n*sizeof(int)) side note ...

  • DOM Manipulation

    Node.appendChild ① 将 img 节点插入到 body 中 ② 移除 body 中的 img 节点...

  • Russia banned from Olympics over

    IOC report confirms ‘‘the systematic manipulation of the ...

  • SQL笔记--(7)--[触发器]

    Classification DML(Data Manipulation Language) Trigger : ...

  • DO DREAMS SETTLE YOUR FUTURE (2)

    Creation and manipulation of dream content is a sensitive...

网友评论

      本文标题:#Lua# Stack Manipulation

      本文链接:https://www.haomeiwen.com/subject/amssottx.html