lua-users home
lua-l archive

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


As usual in debugging, we are into multiple, compounding and confounding
problems! I think I have found the solution. But aso I think I have found a
genuine lua bug (discussed at the end).

To recap what I am doing: I have a CFunction named Include(filename) which
includes a chunk when called from the script. I use this method because I
have path splitting, etc. going on and I am more facile for dealing with
that from C/C++. Originally, the Cfunction contained lua_dofile() which I
thought would do the trick but it was failing. So I switched to
luaL_loadfile() but I forgot to follow with a command to execute the script.
Now I find it works by the standard sequence of lua_loadfile() and
lua_pcall().

One thing that was obscuring the details is that apparently these commands
do not like having a blank last line following comment(s). The included
chunk was failing but I could not get a specific error message to realize
the syntax error on the last line using lua_dofile().
----

LUA BUG?

Here's a possible lua bug that got me off into never-never land with this
problem. There is something about the parsing of the final "invisible"
characters in the file, depending upon what they are. This could also be a
problem with junk CR/LF or other non-printing chars that the editor or the
saving added at the end of the file (should lua correct for that?).  For
example:

I generally put the equivalent of an #ifdef ... #endif container around my
included class definition chunks in case they are called more than once
during the script. Now, if my included chunk looks like this:

if not <classname> then    --//////
...
end    --//////


with one or more CR/LR blank lines after the :end: line, then
luaL_loadfile() fails trying to load it. Presumabely that is also what was
choking lua_dofile, but I wasn't getting the specific error messages I
needed to discover it. But if I remove the CR/LF so that the last line in
the editor is the :end: line, then no load error occurs. For example, if the
:end: is on line 67 and line 68 is empty, here is the luaL_loadfile() error
message:

    (chunk filename) :68: invalid control char new 'char(0)'

If I back up to make the file termiante at the right end of the :end: line,
then there is no error and the script completes. I can repeat this behavior.

----
So, in summary, my original problem seems to be fixed now. I *really*
appreciate all the pointers people have given me.

Michael

----- Original Message ----- 
From: "Ashwin Hirschi" <deery@operamail.com>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Friday, August 20, 2004 3:29 PM
Subject: Re: cannot index a table loaded as a chunk


>
> > The script includes a CFunction named Include which uses luaL_loadfile()
> > to load chunks into the same lua state.
>
> If I understand correctly your main script loads other scripts using your
own Include function, now based on luaL_loadfile.
>
> Are you sure this Include function also _executes_ the scripts that it
loads?
>
> If you changed the old lua_dofile calls here to luaL_loadfile ones, this
isn't the case...  [and you'll have to make sure the chunks are actually
run, like you do in your main routine]
>
> Sorry if I'm stating the obvious: it's tricky to keep track of changes to
someone else's code at a distance [;-)].
>
> Ashwin.
> -- 
> no signature is a signature.
>