1、C++程序中嵌入lua
系列文章
代码
很简单,直接上代码:
simple.lua
print("hello word")
simple.cpp
#include <lua.hpp>
int main (void)
{
lua_State *L = lua_open(); // 打开一个lua状态机
luaopen_base(L); // 加载基本的lua库
luaL_dofile(L, "simple.lua"); // 加载并运行lua脚本
lua_close(L); // 关闭lua状态机
return 0;
}
MakeFile
CFLAG=`pkg-config --cflags lua5.1`
LDFLAG=`pkg-config --libs lua5.1`
CC=g++
all: simple
simple: simple.cpp
$(CC) -o $@ $(CFLAG) $(LDFLAG) $<
测试环境
类型 | 值 |
---|---|
操作系统 | Ubuntu 10.10 |
lua | 5.1.4 |