Any common bug-inducting mistake going from 5.0 to 5.1alpha?

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

Any common bug-inducting mistake going from 5.0 to 5.1alpha?

Marco Pontello-3
I'm loosing some hairs with a problem with my DogLua plugin:
http://mark0.net/plugins-doglua-e.html

All worked well while I was using a Lua 5.0 Win32 DLL.
It's coded in PowerBASIC (witch as no problem interfacing with C, for
example), and I'm using a set of Lua include files and some
wrappers/helpers that I made and used in many other projects.

Then I read about the Lua 5.1 based LuaJIT, and so I modified a bit
the code to use that.
I have to say that the problems I'm seeing don't depend on LuaJIT,
because I get the same errors with the plain Lua 5.1.

What I basically do is:
- Create a New Lua State (with luaL_NewState(), standard memory allocator)
- Register some functions
- Run some Lua script with a LoadString + PCall
- Close the Lua State

One run goes well. The second also.
Then the app crash when the Lua_Close is called, with an access
violation writing to memory that doesn't belong to that process; or it
stall on the Lua_Close (app doesn't respond for some seconds, like if
it was garbage collecting), and then crash on the subsequent
luaL_NewState().

I have to say that, while I'm able to create the binary DLL starting
from the source package, or some trivial things, I'm no expert (by any
means) in C.

I'm almost sure that I'm doing something really stupid :), but I'm a
bit at loss at finding exactly what. So if anyone have gone trough
similar problems when going from 5.0 to 5.1 have some advise / insight
about what to check, I'm all ears.

Thanks,
Bye!
--
Online TrID File Identifier
http://mark0.net/onlinetrid/trid.aspx


Reply | Threaded
Open this post in threaded view
|

Re: Any common bug-inducting mistake going from 5.0 to 5.1alpha?

D Burgess-4
I think you will need to isolate the problem a little more for the list
to help you.

Try compiling your DLL with debug options (assuming you are using
MS VC), the call stack at exception time will be most helpful.

DB

On 9/20/05, Marco Pontello <[hidden email]> wrote:
> I'm loosing some hairs with a problem with my DogLua plugin:
> http://mark0.net/plugins-doglua-e.html
> 
> All worked well while I was using a Lua 5.0 Win32 DLL.
> It's coded in PowerBASIC (witch as no problem interfacing with C, for
> example), and I'm using a set of Lua include files and some
> wrappers/helpers that I made and used in many other projects.
> 
> Then I read about the Lua 5.1 based LuaJIT, and so I modified a bit
> the code to use that.
> I have to say that the problems I'm seeing don't depend on LuaJIT,
> because I get the same errors with the plain Lua 5.1.
> 
> What I basically do is:
> - Create a New Lua State (with luaL_NewState(), standard memory allocator)
> - Register some functions
> - Run some Lua script with a LoadString + PCall
> - Close the Lua State
> 
> One run goes well. The second also.
> Then the app crash when the Lua_Close is called, with an access
> violation writing to memory that doesn't belong to that process; or it
> stall on the Lua_Close (app doesn't respond for some seconds, like if
> it was garbage collecting), and then crash on the subsequent
> luaL_NewState().
> 
> I have to say that, while I'm able to create the binary DLL starting
> from the source package, or some trivial things, I'm no expert (by any
> means) in C.
> 
> I'm almost sure that I'm doing something really stupid :), but I'm a
> bit at loss at finding exactly what. So if anyone have gone trough
> similar problems when going from 5.0 to 5.1 have some advise / insight
> about what to check, I'm all ears.
> 
> Thanks,
> Bye!
> --
> Online TrID File Identifier
> http://mark0.net/onlinetrid/trid.aspx
>


Reply | Threaded
Open this post in threaded view
|

Re: Any common bug-inducting mistake going from 5.0 to 5.1alpha?

Luiz Henrique de Figueiredo
In reply to this post by Marco Pontello-3
> - Register some functions

If you're using luaopen_* to register functions, then this has changed in 5.1:
the luaopen_* functions now should be called using the Lua call protocol not
called directly. See luaL_openlibs linit.c.

--lhf

Reply | Threaded
Open this post in threaded view
|

Re: Any common bug-inducting mistake going from 5.0 to 5.1alpha?

Marco Pontello-3
On 9/20/05, Luiz Henrique de Figueiredo <[hidden email]> wrote:
> > - Register some functions
>
> If you're using luaopen_* to register functions, then this has changed in 5.1:
> the luaopen_* functions now should be called using the Lua call protocol not
> called directly. See luaL_openlibs linit.c.

At the moment I wasn't registering the functions as/in a library, but
something like this:

Lua_PushCClosure(hLuaHandle, pMyFunction, 0)
Lua_PushString(hLuaHandle, STRPTR(pLuaName$))
Lua_Insert(hLuaHandle, -2)
Lua_SetTable(hLuaHandle, %LUA_GLOBALSINDEX)

Maybe that?

Thanks,
Bye!

--
Online TrID File Identifier
http://mark0.net/onlinetrid/trid.aspx


Reply | Threaded
Open this post in threaded view
|

Re: Any common bug-inducting mistake going from 5.0 to 5.1alpha?

Marco Pontello-3
In reply to this post by D Burgess-4
On 9/20/05, David Burgess <[hidden email]> wrote:
> I think you will need to isolate the problem a little more for the list
> to help you.

Yes, you are obviously right.
But I was hoping there was some "common" things that I may/probably
have missing that could cause problem.

Thanks,
Bye!

--
Online TrID File Identifier
http://mark0.net/onlinetrid/trid.aspx


Reply | Threaded
Open this post in threaded view
|

Re: Any common bug-inducting mistake going from 5.0 to 5.1alpha?

Roberto Ierusalimschy
> But I was hoping there was some "common" things that I may/probably
> have missing that could cause problem.

As far as I remember, you can have allocation problems in Windows if you
use Lua both linked statically with lua.exe and dynamically with other
dll's.

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Any common bug-inducting mistake going from 5.0 to 5.1alpha?

Marco Pontello-3
On 9/20/05, Roberto Ierusalimschy <[hidden email]> wrote:
> > But I was hoping there was some "common" things that I may/probably
> > have missing that could cause problem.
>
> As far as I remember, you can have allocation problems in Windows if you
> use Lua both linked statically with lua.exe and dynamically with other
> dll's.

My plugin was using Lua as a DLL, while dealing with the main
application (Dogwaffle) trough an ActiveX server.

Anyway, at the moment I have resolved separating the editor component
and the "real" scripting engine. That probably would had to do anyway,
since it have to be callable by others external editors, or even
trough command line.

Will investigate more at another time.

Thanks to all for the help & hints,
Bye!

--
Online TrID File Identifier
http://mark0.net/onlinetrid/trid.aspx


Reply | Threaded
Open this post in threaded view
|

Newbie questions

Carol Hurwitz
In reply to this post by Roberto Ierusalimschy
I am working on a master's thesis in which I working with a group that has been developing tools that extend the lex/yacc (flex/bison) capabilities. One of those extensions is to handle significant whitespace, which appears in modern languages such as python and javascript Lua falls into that category as it has optional semicolons, and thus newlines become significant. I will be writing flex/bison type files, adapted to our format. The name of the project is Harmonia.[www.cs.berkeley.edu/~harmonia]. We are also working on handling embedded languages, and lua provides us with a good language for testing our tools.

At the moment I am looking at lua from a theoretical point of view, rather than as a programmer. I have written almost no code. I hope to introduce a junior/senior level course in my department with some game programming, at which time, I will have to have actually learned to program in lua. But not until I finish this project!!

Questions:
1. What is the difference between chunk and block grammatically? My understanding is that chunk is the start symbol and that you view a "program" as a chunk, not a block. Within all the productions, only block is used, but since it is defined as a chunk, I don't really understand the intention or the precise meaning of the grammar.

2. Somewhere it is stated that a #-line can be the first line in a chunk so that it can be run as a lua script. The definition of block would mean that you could have such statements sprinkled throughout the the code, i.e., wherever there is a block. Is that what is intended? And is it used that way?

3. How do you do line continuation?  Do you use '\'?

4. Is there a nice little starter set of examples that I could look at? Other than what is in the manual?

Thank you.
Carol




Reply | Threaded
Open this post in threaded view
|

Re: Newbie questions

Aaron Brown-2
Carol Hurwitz wrote:

> What is the difference between chunk and block
> grammatically?

A chunk is a whole file of Lua source code, a string passed
to loadstring, or one line (or multiline block) typed into
the command-line interpreter.  Blocks can be lexically
nested and share upvalues; chunks cannot.

You might have been confused by this statement in the
reference manual:

# syntactically, a block is equal to a chunk

This just means that this code

  print("Hello world!")

could be either a chunk or a block.  If it's the entire
contents of a file given as an argument to the interpreter,
then it's a chunk (and also a block, although one might be
less likely to call it that in this context); if it's in
between a "do" and an "end" (or other control structure
keywords) then it's not a chunk, but it's still a block.

> Somewhere it is stated that a #-line can be the first line
> in a chunk so that it can be run as a lua script.  The
> definition of block would mean that you could have such
> statements sprinkled throughout the the code, i.e.,
> wherever there is a block.

Nope, a "shebang" line only works as the first line of a
chunk as defined above.

> How do you do line continuation?  Do you use '\'?

Inside single-quoted or double-quoted strings, yes, although
the newline right after the backslash becomes part of the
string (if you don't want this, just use .. to concatenate
multiple strings together).  Otherwise, you can break lines
up almost any way you want:

  do

    print ( -- A function call open paren has to be on the
      -- same line as the function call itself.

      "Hello"

      ,

      "world!"

    )

  end


> Is there a nice little starter set of examples that I
> could look at?  Other than what is in the manual?

<http://lua-users.org/wiki/>

-- 
Aaron


Reply | Threaded
Open this post in threaded view
|

Re: Newbie questions

Rici Lake-2
In reply to this post by Carol Hurwitz

On 26-Sep-05, at 7:40 AM, carol.hurwitz wrote:

I am working on a master's thesis in which I working with a group that has been developing tools that extend the lex/yacc (flex/bison) capabilities. One of those extensions is to handle significant whitespace, which appears in modern languages such as python and javascript Lua falls into that category as it has optional semicolons, and thus newlines become significant.

Lua's optional semicolons are not the same as javascript's optional semicolons. (I call the Lua style "semioptional semicolons" :). Newlines are not really significant, except in one case where a newline is an error. See the response to question 3.

I will be writing flex/bison type files, adapted to our format. The name of the project is Harmonia.[www.cs.berkeley.edu/~harmonia]. We are also working on handling embedded languages, and lua provides us with a good language for testing our tools.

At the moment I am looking at lua from a theoretical point of view, rather than as a programmer. I have written almost no code. I hope to introduce a junior/senior level course in my department with some game programming, at which time, I will have to have actually learned to program in lua. But not until I finish this project!!


Personally, I think Lua is a very useful language -- and I've never written a game in my life :)

Questions:
1. What is the difference between chunk and block grammatically? My understanding is that chunk is the start symbol and that you view a "program" as a chunk, not a block. Within all the productions, only block is used, but since it is defined as a chunk, I don't really understand the intention or the precise meaning of the grammar.

In Lua 5.1, a chunk is semantically a function with prototype (...). In previous versions it was semantically a function with prototype (). Syntactically, there is no distinction (but see below).

2. Somewhere it is stated that a #-line can be the first line in a chunk so that it can be run as a lua script. The definition of block would mean that you could have such statements sprinkled throughout the the code, i.e., wherever there is a block. Is that what is intended? And is it used that way?

No, a # comment line can only be the first line in a chunk; this is actually a chunk transformation performed prior to parsing, and is intended to allow the use of Unix #! lines.

3. How do you do line continuation?  Do you use '\'?

Lines are not syntactically significant so there is no need to "do line continuation". However, there are (as always) a few exceptions.

1) Ordinary comments extend from -- to the end of the line. There is no mechanism for continuing such comments (although there is a "long comment" syntax which is explicitly delimited and consequently can cross line endings).

2) Ordinary string literals cannot include line-end characters unless such characters are escaped with \. This introduces a line-end character into the string literal, so it is not really a line continuation character.

3) The grammar includes an ambiguity. Function calls are expressed, as in many languages, with a postfix '(' <expression-list> ') notation. However, there are statements which may end with an expression, and statements which may begin with an expression; this creates a shift-reduce conflict which is resolved in favour of the shift. However, the function-call is a syntactic error if a newline intervenes between the function-expression and the '('. In this case, and only in this case, a ';' must be used to separate the statements.

Example:

The following is a syntactically correct function call statement:

  (a or b)(c or d)(e or f)(g or h)

(That is, it is three consecutive function calls, the first two of which are expected to return a function.)

The grammatical ambiguity introduces the possibility that this could be parsed as two statements:
  (a or b)(c or d); (e or f)(g or h)
but the ambiguity is resolved in favour of shift, so the first interpretation is used.

If two statements were actually desired, it would not be possible to write them with a newline (hence my claim that newlines are not syntactically significant); the following is a syntax error:

  (a or b)(c or d)
-- error
  (e or f)(g or h)

In this case, the use of a semi-colon is necessary; the statements could be written in any of the following ways (amongst others). (I use style (2) in code generation, by the way.)

1)
  (a or b)(c or d); (e or f)(g or h)

2)
  (a or b)(c or d)
  ; (e or f)(g or h)

3)
  (a or b)(c or d);
  (e or f)(g or h)




4. Is there a nice little starter set of examples that I could look at? Other than what is in the manual?

There is a set of test programs in the Lua distribution. Also see Roberto Ierusalimischy's excellent book Programming in Lua (http://www.lua.org/pil/) which has a nice collection of example programs.