dostring(...) on the Mac

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

dostring(...) on the Mac

Jon Kleiser-2
I'd like to describe some Lua problems I've had (and finally solved) on the
Macintosh. To some of you it might be just trivial, but to me it was a
pain.

On the Macintosh I've been building small Lua (3.0) test projects (both 68K
and PPC) based on two different frameworks/libraries, MacZoop and Tools
Plus, using CodeWarrior 10. When I started to use lua_linehook and $debug,
the ones based on MacZoop (C++) did well, but the others, based on Tools
Plus (C), failed quite consistently. Most of all it seemed to be the $debug
pragma, not the presence of my lua_linehook, that was causing the problems.

Fortunately I have a friend who's a real MacsBug specialist, so when I'd
had enough errors, I brought my projects over to his place. He was
observing registers and hex codes for a while, but then he got suspicious
by a fact that I hadn't payed too much attention to: My nice projects only
made use of lua_dofile's, while my problem projects only made use of
lua_dostring's. After a few more minutes it was clear: When you use
lua_dofile's, the Carriage Returns in the Mac files get translated into
Linefeeds; when you use lua_dostring's, they don't. For some reason Lua
thinks Returns are quite OK as long as they don't enclose pragmas like
$debug. We wrote a quick CR-to-LF translator to be used prior to the
lua_dostring calls, and that was it.

A few experiments in the interactive (terminal) Lua, show it quite clearly
(if the backslashes survive the mailing):

dostring("print(1)\nprint(2)")
1
2

dostring("print(1)\rprint(2)")
1
2

dostring("print(1)\n$debug\nprint(2)")
1
2

dostring("print(1)\r$debug\rprint(2)")
prin syntax error;$d
Active Stack:
    function dostring [in file (C)]
    main of (dostring) >> dostring("print(1)\r at line 1

It think a few words on this LF/CR/separator subject would be fine in the
Lua documentation ;)

I'm looking forward to exploring 3.1 (alpha), both on the Mac and the BeBox.

Sincerely,

Jon Kleiser


Reply | Threaded
Open this post in threaded view
|

Re: dostring(...) on the Mac

Luiz Henrique de Figueiredo
>From [hidden email] Mon Jan 19 21:37:46 1998
>lua_dostring's. After a few more minutes it was clear: When you use
>lua_dofile's, the Carriage Returns in the Mac files get translated into
>Linefeeds; when you use lua_dostring's, they don't. For some reason Lua

That's correct and that's what an ANSI C compiler for the Mac should do.
In C, you should *always* use \n as a line separator in strings.

>dostring("print(1)\r$debug\rprint(2)")
>prin syntax error;$d
>Active Stack:
>    function dostring [in file (C)]
>    main of (dostring) >> dostring("print(1)\r at line 1

I get the very same error when I run your example code on a Sun,
which uses \n as end-of-line.
So, the error is correct and expected.

>It think a few words on this LF/CR/separator subject would be fine in the
>Lua documentation ;)

Like I said, you should *always* use \n as a line separator in strings,
as if you were going to write them out.

--lhf