lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



在 2011-7-1 晚上9:02,"Hans van der Meer" <H.vanderMeer@uva.nl>写道:
>
> I am experiencing a strange behaviour in Apple Macintosh XCode when embedding Lua in it.
>
> The relevant code is:
>
>        lua_State *L = luaL_newstate(); luaL_openlibs(L);
>        char *inputstring = "print('Hello!')";
>        int error = luaL_loadstring(L, inputstring);
>        if (error == LUA_ERRSYNTAX)
>                NSLog(@"Return from lua_loadbuffer = LUA_ERRSYNTAX \n");
>        else if (lua_pcall(L, 0, 0, 0)) {
>                NSLog(@"LUA-ERROR: %s\n", lua_tostring(L, -1));
>                lua_pop(L, 1);
>        }
>        lua_close(L);
>
> Running with inputstring = "print('Hello!')" is fine.
> But with "print('Hello!\n')"
Use \\n instead.

luaL_loadstring generates a LUA_ERRSYNTAX:
>
>        2011-07-01 14:51:39.932 EmbeddedLua[1371:a0f] Return from lua_loadbuffer = LUA_ERRSYNTAX
>
> I checked that \n has the value 10. Moreover, in the Terminal-application both prints are running without a problem. Also I checked that the program file is UTF-8.
>
> Why does Lua generates a syntax error on encountering the \n?
> Does someone has an explication?
>
> Hans van der Meer
>
>