代码拉取完成,页面将自动刷新
extern "C" {
#include "include/lua.h"
#include "include/lauxlib.h"
#include "include/lualib.h"
}
#include <iostream>
/*
* 编译样例
* g++ lua_test.cpp -o lua_test.exe -L/usr/local/lib -llua -ldl -I/usr/local
* */
bool run(lua_State* L, std::string in_data) {
lua_getglobal(L, "interpreter");
lua_pushstring(L, in_data.c_str());
lua_call(L, 1, 1);
return lua_toboolean(L, -1);
}
int main(int argc, char* argv[]) {
lua_State* L = luaL_newstate(); // 初始化
luaL_openlibs(L); //
if (luaL_loadfile(L, argv[1]) || lua_pcall(L, 0, 0, 0)) {
std::cout << "error: " << lua_tostring(L, -1) << std::endl;
return 0;
}
std::cout << run(L, "print('123123') return 2 < 3 and 4 < 6") << std::endl;
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。