2

I have a plain text lua table on disk. It looks something like this:

rootTable = {

     name="myTable",

     settings = {
         setting1="some stuff",
         setting2="some more stuff"
     },
     parameters = {
          { name="paramName",  values={x=1.0,y=1.0,z=0.0,w=0.0} },
          { name="paramName2", values={x=0.0,y=3.0,z=1.0,w=0.0} }
     }
}

I'm trying to open up this table in lua (within c++) using the following code:

const char *filename = "path/file.txt"

lua_State *state = luaL_newstate();
luaL_openlibs(state);
int error = luaL_loadfile(state, filename);
if (error == 0) {
    error = lua_pcall(_state, 0, 0, 0);
}
if(error != 0)
{
    std::string errorMessage = lua_tostring(_state, -1);
    fprintf(stderr, "%s\n", _errorMessage.c_str());
}

However whenever I try to run this, I get the following error message:

unexpected symbol near '{'

I don't know what this means or how I can fix it. Any help would be appreciated.

1 Answer 1

2

I don't get any failure loading that table using load/loadstring/loadfile in Lua 5.1, 5.2, or 5.3 (and don't see anything wrong with it). You may be loading a different file than the one you are showing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.