barssala
barssala

Reputation: 483

luaL_dofile Error

Error at line "luaL_dofile" and debugger doesn't show anything about error.

I can use command "luaL_dostring" but I don't know why I can't dofile.

My code is following:

const char* file = "/app_home/data/minigames/mg_hint_machine_2.lua";
ret = luaL_dofile(LS, file);
if(ret != 0){
    PRINTF("Error occurs when calling luaL_dofile() Hint Machine 0x%x\n",ret);
    }
else PRINT("\nDOFILE SUCCESS");

and debugger shows error in this line and "ret" still not get returned value from dofile.

If you want to see about error in debugger

02C2D304 7C21016A stdux r1,r1,r0 03 (02C2D300) REG PIPE LSU

Debugger points in this line and I can't understand it.

Upvotes: 0

Views: 6342

Answers (2)

Michael Anderson
Michael Anderson

Reputation: 73470

As an elaboration on superzilla's answer (upvote that answer rather than this one), to get the error message your code needs to look like this:

const char* file = "/app_home/data/minigames/mg_hint_machine_2.lua";
ret = luaL_dofile(LS, file);
if(ret != 0){
  PRINTF("Error occurs when calling luaL_dofile() Hint Machine 0x%x\n",ret);
  PRINTF("Error: %s", lua_tostring(LS,-1));
}
else PRINT("\nDOFILE SUCCESS");

Your change (in the comments) changed the luaL_dofile to a luaL_dostring, which is why you're getting unexpected error message ( as mentioned here ).

Upvotes: 4

Jackson
Jackson

Reputation: 87

Putting this in the body of your if statement will help us narrow down the problem:

printf("%s\\n",lua_tostring(LS,-1));

It'll tell us what Lua is reporting when it crashes.

Upvotes: 1

Related Questions