# Include "stdafx. H "# include <iostream> extern" C "{# include" Lua. H "# include" lauxlib. H "# include" lualib. H "} # pragma comment (Lib," lua51.lib ") using namespace STD; int luaadd (lua_state * l, int X, int y) {int sum; lua_getglobal (L, "add"); lua_pushnumber (L, x); lua_pushnumber (L, Y); lua_call (l, 2, 1); sum = (INT) lua_tonumber (L,-1 ); lua_pop (L,-1); Return sum;} int _ tmain (INT argc, _ tchar * argv []) {lua_state * l = lual_newstate (); L = lua_open (); lual_openlibs (l); lual_dofile (L, "Hello. lua "); int sum; sum = luaadd (L, 10, 15); cout <sum <Endl; return 0 ;}
Lua scriptCode
------ Two number addfunction add (x, y) return x + y end
You must configure the Lua environment.
Go to the official website to download the Windows-based installation package and install Lua.
ThenProgramThe project contains the Lua header file and library file !!