c++调用lua函数

#include <stdio.h> extern "C"{ #include "lua.h" #include "lualib.h" #include "lauxlib.h" } int main(int argc, char *argv[]) { int s=0; lua_State *L = lua_open(); //load the libs luaL_openlibs(L); //run a lua script here luaL_dofile(L,"foo1.lua"); lua_getglobal(L,"add"); lua_pushnumber(L,2); lua_pushnumber(L,13); lua_call(L,2,1); int iResult = (int)lua_tonumber(L,1); lua_pop(L,1); printf("/t Result: %d/n/n",iResult); lua_close(L); }

 

----foo1.lua--------
function add ( x, y )
return x + y
end

你可能感兴趣的:(C++,c,lua,include)