标签:
编译器:visual studio
首先配置好项目环境
1.引入lua5.1.lib,lub51.lib依赖项
2.引入库目录
3.开始写代码
a.c
#include <lua.h> #include <lualib.h> #include <lauxlib.h> ? int add(lua_State *L) { ????int x = lua_tonumber(L, 1); ????int y = lua_tonumber(L, 2); ????lua_pushnumber(L, x+y); ????return 1; } ? int main() { ????lua_State *L = lua_open(); ????luaL_openlibs(L); ????lua_register(L, "add", add); ????luaL_dofile(L, "a.lua"); ????lua_close(L); ????return 0; ? } |
a.lua
print(add(2,3)) |
?
运行结果:5
标签:
原文地址:http://www.cnblogs.com/bankyh/p/4520770.html