Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 Lua “C” API 函数luaL_loadbuffer()来运行 Lua 代码。
luaL_loadbuffer()
我有一小部分 Lua 块,我多次调用它们。但是每次我调用luaL_loadbuffer()块时都会重新编译。这似乎非常低效。块引用的大部分代码都是预编译的,但是为什么我每次都需要重新编译块本身呢?我怎样才能避免这种重新编译?
我可以将预编译的块传递给luaL_loadbuffer()吗?
我可以制作返回的 Lua 堆栈的完整副本并重新使用它吗?
还有其他聪明的方法吗?
继续用于luaL_loadbuffer加载脚本。此处加载意味着预编译。只需将留在堆栈中的函数保存在程序中的某个位置(或者如果可以的话,将其留在堆栈中)。到了运行脚本的时候lua_pushvalue了lua_pcall。
luaL_loadbuffer
lua_pushvalue
lua_pcall
用于luaL_loadstring加载您使用 luac 预编译的二进制块。但请注意 - 这些二进制文件不能跨平台或 Lua 版本移植。
luaL_loadstring