Erik Lindroos | 1 Jul 09:22 2009
Picon

Re: lua_replace finding

On Thu, Jun 25, 2009 at 12:53 PM, Jerome Vuarand <jerome.vuarand <at> gmail.com> wrote:
[...]
On the other hand I agree the current behaviour of lua_replace(L,
lua_gettop(L)) is counter-intuitive. IMHO it should either be a no-op
or throw an error.

It should not be a no-op. Functions that result in different stack depths, especially without producing an error, are very annoying.
Wim Paulussen | 1 Jul 18:07 2009
Picon

Installed lua , luarocks and Nanoki - luasocket not found - newbie

I recently discovered the existence of lua and want to investigate more
about what I could do with it.

I installed Lua (5.1.4 - built on Centos ), installed luarocks and Nanoki.
I also installed the required modules (filesystem, luasocket, lzlib and
slncrypto) . 'luarocks list' displays these modules as installed. so far,
I did not get any error messages, so I assumed everything is OK.

When trying to launch Nanoki, I get the following 'lua:
./TCPServer.lua:15: module 'socket' not found: ....(more error messages
about files not found) '
As far as I can see this means that socket.lua, although present, cannot
be found by lua.

Also, I do not have a LUA_PATH variable set. Anyone able to point me in
the right direction ?

Thank you very much in advance.

Hisham | 1 Jul 18:42 2009
Picon

Re: Installed lua , luarocks and Nanoki - luasocket not found - newbie

On Wed, Jul 1, 2009 at 1:07 PM, Wim Paulussen<wim <at> asgc.be> wrote:
> I recently discovered the existence of lua and want to investigate more
> about what I could do with it.
>
> I installed Lua (5.1.4 - built on Centos ), installed luarocks and Nanoki.
> I also installed the required modules (filesystem, luasocket, lzlib and
> slncrypto) . 'luarocks list' displays these modules as installed. so far,
> I did not get any error messages, so I assumed everything is OK.
>
> When trying to launch Nanoki, I get the following 'lua:
> ./TCPServer.lua:15: module 'socket' not found: ....(more error messages
> about files not found) '
> As far as I can see this means that socket.lua, although present, cannot
> be found by lua.
>
> Also, I do not have a LUA_PATH variable set. Anyone able to point me in
> the right direction ?

First, check if luarocks.require is in Lua's module path. You can do
this by launching the interpreter in the command line and doing:

require("luarocks.require")

if that returns no error messages, you should be ok. (You should also
be able to do require("socket") after loading luarocks.require). If
you did a default install of Lua and LuaRocks that should be already
the case. If it fails, you should edit your LUA_PATH variable (there
should be documentation around on how to edit this, somewhere).

If you're able to load luarocks.require, then the next question is:

How did you launch the script? The luarocks.require module needs to be
loaded in order for modules to be found, so if you did

lua ./TCPServer.lua

then you should do

lua -lluarocks.require ./TCPServer.lua

and if the script is executable and you launched it with

./TCPServer.lua

then you should edit its first line from something like

#!/usr/bin/lua

to something like

#!/usr/bin/lua -lluarocks.require

Let us know if you still have problems.

-- Hisham

Petite Abeille | 1 Jul 18:46 2009
Picon

Re: Installed lua , luarocks and Nanoki - luasocket not found - newbie

Hi Wim,

On Jul 1, 2009, at 6:07 PM, Wim Paulussen wrote:

> When trying to launch Nanoki, I get the following 'lua:
> ./TCPServer.lua:15: module 'socket' not found: ....(more error  
> messages
> about files not found) '
> As far as I can see this means that socket.lua, although present,  
> cannot
> be found by lua.

What's in your package.path?

E.g.:

% lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
 > print( package.path )
./?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/ 
init.lua;/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/init.lua

socket.lua should be in one of the directories defined in  
package.path... alternatively... copy all the *.lua files in the same  
directory and run everything from there, e.g.:

% cp *.lua Nanoki
% cd Nanoki
% lua Nanoki.lua . 0 1080
2009-07-01 16:45:32 Version 	 Nanoki/1.13
2009-07-01 16:45:32 Location 	 .
2009-07-01 16:45:32 Server 	 tcp 0 1080
2009-07-01 16:45:32 Forwarded 	 false
2009-07-01 16:45:32 Secure 	 false

HTH.

Cheers,

PA.

Wim Paulussen | 2 Jul 08:32 2009
Picon

Installed lua , luarocks and Nanoki - luasocket not found - newbie

Dear Hisham and Petitte Abeille,

Even a newbie on mailing lists !

Thanks to your info I got it working now. But again a question too : my
package.path returns nil : is this something to worry about ?

Wim Paulussen

Watusimoto | 2 Jul 10:04 2009

Lunar, C++, and premature object destruction

I'm working on a game that uses Lua to control robot players, written in 
C++, and bound with Lunar, and am having problems controlling the 
lifespan of objects created in C++ and referenced in Lua.  (It's at 
http://bitfighter.org, if you are curious, and the linked wiki contains 
examples of some robot scripts.)

My primary object is a Ship.  The lifetime of the Ship object is 
completely controlled by C++.  I also have a proxy object, called 
LuaShip, that contains a pointer to the Ship, and handles all the 
requests for information about the Ship from the Lua script.  The goal 
is that when the Ship is destroyed, the pointer on the LuaShip will be 
set to NULL, and any future requests to the LuaShip can be intelligently 
handled (probably by generating an error of some sort).  The LuaShip is 
exposed to Lua via Lunar if the robot script requests it (using a 
getShip() method or somesuch).

The Ship object also contains a pointer to its LuaShip proxy.  My 
problem is that when the Ship object is destroyed, C++ seems to think 
that all pointers to the LuaShip are gone, and it is OK to destroy the 
LuaShip as well.  It does not seem to recognize when a Lua instance is 
also referring to the LuaShip.  The result is that the LuaShip is 
destroyed, and the Lua script is now left holding a reference to 
nothing.  When the script acts on it (thinking it's still valid), the 
app crashes.

My questions are 1) Is this an appropriate architecture for managing Lua 
instances that can have persistent references to C++ objects (Ship in 
this case) that can be deleted without warning, and 2) are there any 
good examples of code that uses Lunar in this manner that I can examine 
to see where my problem might be?

Thank you,

Chris

Thomas Lauer | 2 Jul 13:03 2009
Picon

[ANN] Lua Short Reference, minor upgrade

The Lua short reference provides a concise summary of the Lua syntax and
core libraries. I have just updated and uploaded another draft of the
5.1 version. This can be downloaded from either the lua-users.org wiki:

http://lua-users.org/wiki/LuaShortReference

or from my website:

http://thomaslauer.com/comp/Lua_Short_Reference

A few small errors and inconsistencies were removed. However, there are
certainly still errors and omissions to be found in this draft. PLEASE,
everyone who uses this card -- take the time and trouble to send a bug
report if you happen on something that needs correcting. (BTW, the
exclusion of deprecated language features (like table.setn()) is by
design.)

Acknowledgements: Enrico Colombini (the original author) and I are
grateful to all the good people who contributed with notes and
suggestions, including John Belmonte, Albert-Jan Brouwer, Tiago
Dionizio, Marius Gheorghe, Asko Kauppi, Philippe Lhoste, Mike Pall,
Virgil Smith, Ando Sonenblick, Nick Trout, Clemens Wacha, Blake T.
Garretson, mbp, James Salsman and of course Roberto Ierusalimschy, whose
“Lua 5.1 Reference Manual” and “Programming in Lua” have been our main
sources of Lua lore.

--

-- 
cheers  thomasl

web : http://thomaslauer.com/start

Duncan Cross | 2 Jul 13:59 2009
Picon

Re: [ANN] Lua Short Reference, minor upgrade

On Thu, Jul 2, 2009 at 12:03 PM, Thomas Lauer<thomas.lauer <at> virgin.net> wrote:
> The Lua short reference provides a concise summary of the Lua syntax and
> core libraries. I have just updated and uploaded another draft of the
> 5.1 version. This can be downloaded from either the lua-users.org wiki:
>
> http://lua-users.org/wiki/LuaShortReference
>
> or from my website:
>
> http://thomaslauer.com/comp/Lua_Short_Reference
>
> A few small errors and inconsistencies were removed. However, there are
> certainly still errors and omissions to be found in this draft. PLEASE,
> everyone who uses this card -- take the time and trouble to send a bug
> report if you happen on something that needs correcting. (BTW, the
> exclusion of deprecated language features (like table.setn()) is by
> design.)
>
> Acknowledgements: Enrico Colombini (the original author) and I are
> grateful to all the good people who contributed with notes and
> suggestions, including John Belmonte, Albert-Jan Brouwer, Tiago
> Dionizio, Marius Gheorghe, Asko Kauppi, Philippe Lhoste, Mike Pall,
> Virgil Smith, Ando Sonenblick, Nick Trout, Clemens Wacha, Blake T.
> Garretson, mbp, James Salsman and of course Roberto Ierusalimschy, whose
> “Lua 5.1 Reference Manual” and “Programming in Lua” have been our main
> sources of Lua lore.
>
> --
> cheers  thomasl
>
> web : http://thomaslauer.com/start
>

Thank you for maintaining this, it is very useful having this kind of
"cheat-sheet", particularly for getting people who are good at programming but
just not that familiar with Lua yet up to speed quickly.

I have noticed a few things just skimming it now:
  - One of the table constructors {[-900] = 3, [+900] = 4} - Lua actually does
    not support the "unary plus" and throws a parse error at this.
  - Potential for confusion, maybe:

      x:move (2, -3)
      object call: shortcut for x.move(x, 2, -3), x will be assigned to self

    ..."x will be assigned to self", only if x.move was also created using the
    same syntax. Someone could misread this as 'whatever parameter was named
    "self", wherever it appears in the parameter list, will be set to x'.
  - setmetatable and setfenv returns the table/function, I don't know if you'd
    consider this worth mentioning in this but I find it quite useful
  - string.byte also allows two parameters to get the numerical code of each
    character in a range
  - Would it be worth mentioning how strings by default have a metatable set
    allowing for method calls that use the string table (and how you can use
    it on string literals only if you put them in parentheses)?

-Duncan

Thomas Lauer | 2 Jul 15:10 2009
Picon

Re: [ANN] Lua Short Reference, minor upgrade

Duncan Cross <duncan.cross <at> gmail.com> wrote:

> I have noticed a few things just skimming it now:
>   - One of the table constructors {[-900] = 3, [+900] = 4} - Lua actually does
>     not support the "unary plus" and throws a parse error at this.

Ack and changed.

>   - Potential for confusion, maybe:
> 
>       x:move (2, -3)
>       object call: shortcut for x.move(x, 2, -3), x will be assigned to self
> 
>     ..."x will be assigned to self", only if x.move was also created using the
>     same syntax. Someone could misread this as 'whatever parameter was named
>     "self", wherever it appears in the parameter list, will be set to x'.

What wording would you propose instead? Perhaps removing the "x will be
assigned to self" altogether?

>   - setmetatable and setfenv returns the table/function, I don't know if you'd
>     consider this worth mentioning in this but I find it quite useful

setmetatable: ack and changed.

setfenv: the manual says "As a special case, when f is 0 setfenv changes
the environment of the running thread. In this case, setfenv returns no
values." So I'll leave it as it is.

>   - string.byte also allows two parameters to get the numerical code of each
>     character in a range

Ack and changed.

>   - Would it be worth mentioning how strings by default have a metatable set
>     allowing for method calls that use the string table (and how you can use
>     it on string literals only if you put them in parentheses)?

I've included a note to that effect.

Thanks for reporting. I'm going to wait a few more days for possible
further feedback and then go ahead with a new draft.

--

-- 
cheers  thomasl

web: http://thomaslauer.com/start

Duncan Cross | 2 Jul 15:51 2009
Picon

Re: [ANN] Lua Short Reference, minor upgrade

On Thu, Jul 2, 2009 at 2:10 PM, Thomas Lauer<thomas.lauer <at> virgin.net> wrote:
>>   - Potential for confusion, maybe:
>>
>>       x:move (2, -3)
>>       object call: shortcut for x.move(x, 2, -3), x will be assigned to self
>>
>>     ..."x will be assigned to self", only if x.move was also created using the
>>     same syntax. Someone could misread this as 'whatever parameter was named
>>     "self", wherever it appears in the parameter list, will be set to x'.
>
> What wording would you propose instead? Perhaps removing the "x will be
> assigned to self" altogether?

I think so. I'd also specify in the "Function definition" section that self is
an extra *first* argument. (The reason I think that it is useful to
deconstruct the syntactic sugar a little bit here is that sometimes I want to
define a function inside a {} table literal, and of course in that situation
you have to add the "self" parameter explicitly.)

>>   - setmetatable and setfenv returns the table/function, I don't know if you'd
>>     consider this worth mentioning in this but I find it quite useful
>
> setmetatable: ack and changed.
>
> setfenv: the manual says "As a special case, when f is 0 setfenv changes
> the environment of the running thread. In this case, setfenv returns no
> values." So I'll leave it as it is.

True, I had forgotten about this extra complication.

Some additional notes:
  - Multi-line strings: One thing that is easy to forget is that if it starts
    immediately with a new line, that new line is removed. (You also don't
	mention the variable number of =s, but you do for multi-line comments,
	maybe this is deliberate.)
  - Decimal escape sequence can have one or two digits instead of three, again
    not mentioning this might be deliberate.
  - Very minor: "nil" not bolded in coroutine.running()
  - The __len metamethod is (currently) only used by userdata.

-Duncan


Gmane