test.lua文件
print("hello lua")
width=200
height=300
weight="this is String"
function max(num1,num2 )
if(num1>num2)then
return num1
else
return num2
end
end
C++ 代码
#include<stdio.h>
#include<stdlib.h>
extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
#pragma comment(lib, "lua53.lib")//这个是在官网下载后源文件编译生成的静态库
lua_State *L;
double Cmax(double x, double y) {
lua_getglobal(L, "max");
lua_pushnumber(L, x);
lua_pushnumber(L, y);
if (lua_pcall(L, 2, 1, 0) != 0) {
printf( "error running function 'f': %s\n", lua_tostring(L, -1));
}
if(!lua_isnumber(L,-1))
printf("function 'f' must return a number\n");
double z = lua_tonumber(L, -1);
lua_pop(L, 1);
return z;
}
lua_Integer getLu