简体   繁体   中英

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.

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 ).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM