美文网首页
Lua 中的API

Lua 中的API

作者: 程序手艺人 | 来源:发表于2018-01-18 14:19 被阅读11次

luaL_newstate

  • lua_State *luaL_newstate (void);
  • 创建一个新的state

luaL_openlibs

  • void luaL_openlibs (lua_State *L);
  • 打开所有的标准lua库到指定状态,也就是把所有标准类库加载到指定的虚拟机.

luaL_loadfile

lua_pcall

  • int lua_pcall (lua_State *L, int nargs, int nresults, int msgh);
  • 在保护模式下调用一个函数

lua_getglobal

  • void lua_getglobal (lua_State *L, const char *name);
  • 将全局名称的值压入堆栈

lua_newtable

  • void lua_newtable (lua_State *L);
  • 创建一个新的table并将其推入堆栈,它等价于lua_createtable(L, 0, 0).

lua_pushliteral

  • const char *lua_pushliteral (lua_State *L, const char *s);
  • 这个宏相当于lua_pushstsring,但只能在s是一个字符串时使用,它会自动提供字符串的长度.

lua_settable

  • void lua_settable (lua_State *L, int index);
  • 就是把表在lua堆栈中的值弹出来,index 是table 在堆栈中的位置,假如 table 在 -3, 则key 应该是 -2,value 是 -1
    相当于 table[key] = value.

lua_call

  • void lua_call (lua_State *L, int nargs, int nresults);
  • 调用一个函数
  • nargs是你推入堆栈的参数个数. 函数调用时,所有参数和函数值从堆栈弹出.

相关文章

网友评论

      本文标题:Lua 中的API

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