Table-related APIs

Source: Internet
Author: User

void Lua_getglobal (lua_state *l, const char *name);
Gets the LUA global variable, which pushes the global name of Lua to the stack.
Stack +1

void Lua_setglobal (lua_state *l, const char *name);
Set the LUA global variable, pop a value, and set it to the value of global name.
Stack-1

void Lua_createtable (lua_state *l, int narr, int nrec);
Creating an empty table and pressing the stack will pre-allocate space based on the parameters, and if you know how large the table will be, pre-allocated performance will be better.
Stack +1

void Lua_newtable (Lua_state *l);
Create empty table and press stack, equivalent to lua_createtable (L, 0, 0)
Stack +1

void Lua_gettable (lua_state *l, int index);
Gets the values in the Lua table, T[k] presses the stack, T represents the table in the stack to which index is pointing, and K represents the index that is stored at the top of the stack.
(1) Stack top index key out of the stack, (2) and then stack the value of T[k], (3) in LUA will trigger the Metamethod index event.
The stack size is the same

void Lua_settable (lua_state *l, int index);
Set the values in the LUA table, perform the t[k]=v operation, T represents the table in the stack to which index is pointing, V represents the value at the top of the stack, and K represents the index key stored under V.
(1) v and K will be out of the stack, (2) in LUA will trigger the Metamethod NewIndex event.
Stack-2

void Lua_getfield (lua_state *l, int index, const char *k);
T[K] into the stack, T represents the table in the stack to which index is pointing, triggering the Metathod.index event.
Stack +1

void Lua_setfield (lua_state *l, int index, const char *k);
For the t[k]=v operation, T represents the table in the stack to which index is pointing, and V represents the value at the top of the stack.
(1) Stack top v will be out of the stack, (2) in LUA will trigger the Metamethod.newindex event.
Stack-1

void Lua_rawget (lua_state *l, int index);
Similar to lua_gettable, but does not trigger metatable.
Stack does not change

void Lua_rawset (lua_state *l, int index);
Similar to lua_settable, but does not trigger metatable.
Stack-2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.