1、Lua通过ANSI C 进行编写,Lua与C交互要遵循一定的协议规则。在Lua 5.1 Reference Manual中明确规定如何通过C Code调用Lua 编写的函数。
C code可以调用Lua Code编写的任何函数.本文主要以全局函数来做演示。
2、首先把C语言调用Lua 函数的协议规则说明。Lua 5.1 Reference Manual 中关于void lua_call (lua_State *L, int nargs, int nresults); 函数的描述中详细说明了协议规则。
void lua_call (lua_State *L, int nargs, int nresults);
To call a function you must use the following protocol:
first, the function to be called is pushed onto the stack;
then, the arguments to the function are pushed in direct order;
that is, the first argument is pushed first.
Finally you call lua_call;
nargs
is the number of arguments that you pushed onto the stack.
All arguments and the function value are popped from the stack when the function is called.
The function results are pushed onto the st