#include <iostream>
extern "C" { #include "lua.h" #include "lauxlib.h" #include "lualib.h" }
int main(int argc, char** argv) { std::cout << "Hello World!\n"; int status, result; lua_State* L = luaL_newstate(); /* create state */ if (L == NULL) { //l_message(argv[0], "cannot create state: not enough memory"); return EXIT_FAILURE; } std::string cmd = "a = 7+11"; int r = luaL_dostring(L, cmd.c_str());
if (r == LUA_OK) { lua_getglobal(L, "a"); if (lua_isnumber(L, -1)) { float a_in_cpp = (float)lua_tonumber(L, -1); std::cout << "a_in_cpp = " << a_in_cpp << std::endl; } } else { std::string errormsg = lua_tostring(L, -1); std::cout << errormsg << std::endl; }
//luaL_dofile(L, "xxx.lua")
lua_close(L); }
|