I finally was able to get Lua running with my compiler using C++. I now tried starting some tutorials and the first program won’t do anything. I downloaded the code they used and it still did nothing. No errors however. Test prints out fine but I get no response from the luaL_dostring. I am using v5.1.4-46. Is it possible that i installed it incorrectly in some way that doesn’t result in errors? I printed out the memory address of the lua state and that seems to be working. If someone could give me some sample code to run I would really appreciate it.
Here’s the code:
#include <lua.hpp>
#include <iostream>
#include <string>
using namespace std;
int main()
{
lua_State *L = lua_open();
luaL_openlibs(L);
cout << "Test" << endl;
luaL_dostring(L, "print(\"Hello from Lua!\n\")");
lua_close(L);
return 0;
}
Your dostring syntax generates invalid Lua code… “\n” gets passed to lua parser before execution. you need a “\\n”… think so. So your “luaL_dostring” error code is actually a syntax fault. funny thing…
you should not use dostring for more than testing.