Will Metcalf | 1 Aug 2011 04:10
Picon
Gravatar

Re: electronic copy of "Programming in Lua, Second Edition" textbook on the net

> and if there was an electronic version on sale, I would long
> have bought it.

You can buy an electronic copy of this book.

http://store.feistyduck.com/products/programming-in-lua

Regards,

Will

On Sun, Jul 31, 2011 at 9:42 AM, Marc Balmer <marc <at> msys.ch> wrote:
> Am 18.07.11 15:04, schrieb Vadim Peretokin:
>
>> That's rather distasteful.
>
> This is a sidenote only.
>
> Since many of you are coming to Switzerland later this year, let me
> explain you an interesting facet of Swiss law.  In Switzerland,
> downloads are legal.  We can legally download movies, musics, or in this
> case books, that someone puts online.  It does not matter if the
> publication itself was legal.  The pure act of downloading a copyrighted
> work is legal here.
>
> Of course, publishing of such work is prohibited.  But we are allowed to
> shared content of any matter with friends and family.
>
> What is the conclusion?  I have now legally obtained an electronic copy
> of a book I already bought four or five times in print (for myself, my
(Continue reading)

STPeters | 1 Aug 2011 05:10

Any luafcgid or lua-PgSQL users - input requested

I am just checking to see if there are any current users of these two 
projects:

https://github.com/STPeters/luapgsql
https://github.com/STPeters/luafcgid

I am currently refreshing them and attending to any outstanding issues, 
at the request of a client. If there are any current (or potential) 
users around that need something changed or fixed, just let me know. 
After this round of commits, I may not get around to it for another year.

I know I can be a bit of a ghost at times, but remember - some of us do 
not code for a living anymore.

Maxime Chupin | 1 Aug 2011 10:09
Picon

n-queens -> save the solutions

Hi !

I am playing with the n-queen problem to learn Lua. I want to save all the solution in a list (solutions) but it does not work and I do not understand why. Here my very simple code with which my problem is more understandable.

Thanks for your help.

local N=6

local solutions={}

function NQueen(q,r)
   if r==N+1 then
      -- debug
      char=""
      for e=1,N do
         char=char..q[e].." "
      end
      print(char.."\n") -- THIS PRINT THE RIGHT ARRAYS
      -- end debug
      solutions[#solutions+1]=q
   else
      for j=1,N do
         valid=true
         for i=1,(r-1) do
            if ((q[i]==j or math.abs(q[i]-j)==math.abs(r-

i)) and r>1) then
               valid=false
            end
         end
         if valid then
            q[r]=j
            NQueen(q,r+1)
         end
      end
   end
end

Dq={}
for i=1,N do
  Dq[i]=0
end

NQueen(Dq,1)
print(#solutions.." solutions found") -- RIGHT NUMBER OF SOLUTIONS
local drawSol=solutions[2]
local char=""
for f=1,N do
   char=char..drawSol[f].." "
end
print(char) -- THIS PRINT A WRONG ARRAY



--
Maxime Chupin
http://mc.notezik.com
Dimiter "malkia" Stanev | 1 Aug 2011 10:25
Picon

Re: [LuaJIT FFI] Recommended policy for exposing FFI functions

Hi Duncan,

	First I'm not your general lua user, or long time lua coder, nor a long 
or so active member of this very awesome lua community.

	As for exposing it, I'm going with no hiding whatsoever, in fact I try 
to reuse native types where I go, and actually use them as "first" class 
citizens (more like H1B workers, but eventually getting green cards at 
some point:)).

	But not always. I have found that string handling is better than better 
in lua for what I need, so instead of keeping "char[?]" or "char*[?]" 
around, I might convert result back to string, or return table of it.
	
	So I'm being dualistic - I use certain things directly in FFI - 
vectors, matrices, and others in Lua - table with strings, or 
properties, etc. I don't even have problem keeping what starts from 0 or 
from 1 - as I clearly keep the distinction between two of them (I know 
luajit is efficient with normal lua tables starting from 0, but certain 
lua idioms fail to be understood at this point, which would not apply 
for the luajit array cases, I'm talking about t[ #t + 1 ] = value, and 
possibly others).

	Now again, I don't see myself as regular user (yet), but LuaJIT so far, 
and my goals do not go in the same direction of established developments 
such as luarocks, or others. I even go and recompile the libraries in 
ways that allow me better reuse (for example had to turn off #pragma 
pack(4) for Windows (MSVC) SDL 64-bit build - as it simply made no sense 
- keeping 4 bytes less here and there for miniscule structure, and then 
only for certain compilers).

	I'm still thinking of how to structure my ffi bindings, and extensions 
for them for more lua native usage. Should my extension be given as 
parameter the ffi lib, or should they rely on globally finding them? 
Would it be better instead of directly returning the dll library, return 
a table with the library and additional extension interface, putting the 
two above together? I dunno yet.

Thanks,
Dimiter "malkia" Stanev

On 7/31/11 10:35 AM, Duncan Cross wrote:
> Should a module that uses FFI (but is intended to be used by
> "FFI-blind" code) ever expose actual FFI-bound functions directly, or
> should it instead wrap them in Lua functions?
>
> The reason I ask is that it seems to me there are a couple of reasons
> that you cannot trust FFI-bound functions to be passed around as
> first-class values to arbitrary, "FFI-blind" code:
> 1. type(func) will be 'cdata', not 'function'. (of course, values that
> try to make use of the __call metamethod already have similar
> problems...)
> 2. Perhaps more seriously, == or ~= comparisons that involve an FFI
> function are very likely to throw an "invalid comparison" error, which
> FFI-blind code will not be expecting.
>
> ...and maybe more that I haven't thought of. What do people think
> about this? I am quite keen that only code that directly deals with
> FFI should have to know any of the details of it, so this kind of
> thing seems important.
>
> -Duncan
>
>

Dimiter "malkia" Stanev | 1 Aug 2011 10:30
Picon

Re: electronic copy of "Programming in Lua, Second Edition" textbook on the net

I actually want to buy the book (electronic PDF copy).

I'm in US - is Feisty Duck the only store that sells it?

Thanks!

On 7/31/11 7:10 PM, Will Metcalf wrote:
>> and if there was an electronic version on sale, I would long
>> have bought it.
>
> You can buy an electronic copy of this book.
>
> http://store.feistyduck.com/products/programming-in-lua
>
> Regards,
>
> Will
>
> On Sun, Jul 31, 2011 at 9:42 AM, Marc Balmer<marc <at> msys.ch>  wrote:
>> Am 18.07.11 15:04, schrieb Vadim Peretokin:
>>
>>> That's rather distasteful.
>>
>> This is a sidenote only.
>>
>> Since many of you are coming to Switzerland later this year, let me
>> explain you an interesting facet of Swiss law.  In Switzerland,
>> downloads are legal.  We can legally download movies, musics, or in this
>> case books, that someone puts online.  It does not matter if the
>> publication itself was legal.  The pure act of downloading a copyrighted
>> work is legal here.
>>
>> Of course, publishing of such work is prohibited.  But we are allowed to
>> shared content of any matter with friends and family.
>>
>> What is the conclusion?  I have now legally obtained an electronic copy
>> of a book I already bought four or five times in print (for myself, my
>> company, for friends etc.) and I admit that this comes in as a handy
>> reference for my personal use.  I have no intent to circulate this file,
>> of course, and if there was an electronic version on sale, I would long
>> have bought it.
>>
>> So, distasteful or not, in some legislations, downloading the file in
>> question is perfectly legal.
>>
>>
>>
>>
>>
>
>

Dimiter "malkia" Stanev | 1 Aug 2011 10:41
Picon

Re: n-queens -> save the solutions

Hi Maxime,

You need to story a copy of your "q" array, because it gets modified later.

local N=6

local solutions={}

function NQueen(q,r)
    if r==N+1 then
       -- debug
       char=""
       local qcopy = {}
       for e=1,N do
          char=char..q[e].." "
	 qcopy[e] = q[e]
       end
       print(char.."\n") -- THIS PRINT THE RIGHT ARRAYS
       -- end debug
       solutions[#solutions+1]=qcopy
    else
       for j=1,N do
          valid=true
          for i=1,(r-1) do
             if ((q[i]==j or math.abs(q[i]-j)==math.abs(r-i)) and r>1) then
                valid=false
             end
          end
          if valid then
             q[r]=j
             NQueen(q,r+1)
          end
       end
    end
end

Dq={}
for i=1,N do
   Dq[i]=0
end

NQueen(Dq,1)
print(#solutions.." solutions found") -- RIGHT NUMBER OF SOLUTIONS
local drawSol=solutions[2]
local char=""
for f=1,N do
    char=char..drawSol[f].." "
end
print(char) -- THIS PRINT A WRONG ARRAY

Thanks,
Dimiter "malkia" Stanev.

On 8/1/11 1:09 AM, Maxime Chupin wrote:
> local N=6
>
> local solutions={}
>
> function NQueen(q,r)
>     if r==N+1 then
>        -- debug
>        char=""
>        for e=1,N do
>           char=char..q[e].." "
>        end
>        print(char.."\n") -- THIS PRINT THE RIGHT ARRAYS
>        -- end debug
>        solutions[#solutions+1]=q
>     else
>        for j=1,N do
>           valid=true
>           for i=1,(r-1) do
>              if ((q[i]==j or math.abs(q[i]-j)==math.abs(r-
> i)) and r>1) then
>                 valid=false
>              end
>           end
>           if valid then
>              q[r]=j
>              NQueen(q,r+1)
>           end
>        end
>     end
> end
>
> Dq={}
> for i=1,N do
>    Dq[i]=0
> end
>
> NQueen(Dq,1)
> print(#solutions.." solutions found") -- RIGHT NUMBER OF SOLUTIONS
> local drawSol=solutions[2]
> local char=""
> for f=1,N do
>     char=char..drawSol[f].." "
> end
> print(char) -- THIS PRINT A WRONG ARRAY
>
>

Olivier Galibert | 1 Aug 2011 10:41
Picon
Favicon

Re: n-queens -> save the solutions

On Mon, Aug 01, 2011 at 09:09:00AM +0100, Maxime Chupin wrote:
> I am playing with the n-queen problem to learn Lua. I want to save all the
> solution in a list (solutions) but it does not work and I do not understand
> why. Here my very simple code with which my problem is more understandable.

You're saving a reference to q (and hence to Dq), not a copy of q.  So
your solutions array will end up with a bunch of references to Dq,
which itself will be set at the final queen position.

Best,

  OG.

Alexander Gladysh | 1 Aug 2011 10:44
Picon
Gravatar

Re: electronic copy of "Programming in Lua, Second Edition" textbook on the net

On Mon, Aug 1, 2011 at 12:30, Dimiter "malkia" Stanev <malkia <at> gmail.com> wrote:
> I actually want to buy the book (electronic PDF copy).
>
> I'm in US - is Feisty Duck the only store that sells it?

I'm surprised that there is no Kindle edition on Amazon.

Alexander.

> On 7/31/11 7:10 PM, Will Metcalf wrote:
>>>
>>> and if there was an electronic version on sale, I would long
>>> have bought it.
>>
>> You can buy an electronic copy of this book.
>>
>> http://store.feistyduck.com/products/programming-in-lua
>>
>> Regards,
>>
>> Will
>>
>> On Sun, Jul 31, 2011 at 9:42 AM, Marc Balmer<marc <at> msys.ch>  wrote:
>>>
>>> Am 18.07.11 15:04, schrieb Vadim Peretokin:
>>>
>>>> That's rather distasteful.
>>>
>>> This is a sidenote only.
>>>
>>> Since many of you are coming to Switzerland later this year, let me
>>> explain you an interesting facet of Swiss law.  In Switzerland,
>>> downloads are legal.  We can legally download movies, musics, or in this
>>> case books, that someone puts online.  It does not matter if the
>>> publication itself was legal.  The pure act of downloading a copyrighted
>>> work is legal here.
>>>
>>> Of course, publishing of such work is prohibited.  But we are allowed to
>>> shared content of any matter with friends and family.
>>>
>>> What is the conclusion?  I have now legally obtained an electronic copy
>>> of a book I already bought four or five times in print (for myself, my
>>> company, for friends etc.) and I admit that this comes in as a handy
>>> reference for my personal use.  I have no intent to circulate this file,
>>> of course, and if there was an electronic version on sale, I would long
>>> have bought it.
>>>
>>> So, distasteful or not, in some legislations, downloading the file in
>>> question is perfectly legal.
>>>
>>>
>>>
>>>
>>>
>>
>>
>
>
>

Dimiter "malkia" Stanev | 1 Aug 2011 10:48
Picon

Re: electronic copy of "Programming in Lua, Second Edition" textbook on the net

	I wish I had Kindle, but I do have iPad and Android phone :)

	If nothing else I'll buy it from the store above.

On 8/1/11 1:44 AM, Alexander Gladysh wrote:
> On Mon, Aug 1, 2011 at 12:30, Dimiter "malkia" Stanev<malkia <at> gmail.com>  wrote:
>> I actually want to buy the book (electronic PDF copy).
>>
>> I'm in US - is Feisty Duck the only store that sells it?
>
> I'm surprised that there is no Kindle edition on Amazon.
>
> Alexander.
>
>> On 7/31/11 7:10 PM, Will Metcalf wrote:
>>>>
>>>> and if there was an electronic version on sale, I would long
>>>> have bought it.
>>>
>>> You can buy an electronic copy of this book.
>>>
>>> http://store.feistyduck.com/products/programming-in-lua
>>>
>>> Regards,
>>>
>>> Will
>>>
>>> On Sun, Jul 31, 2011 at 9:42 AM, Marc Balmer<marc <at> msys.ch>    wrote:
>>>>
>>>> Am 18.07.11 15:04, schrieb Vadim Peretokin:
>>>>
>>>>> That's rather distasteful.
>>>>
>>>> This is a sidenote only.
>>>>
>>>> Since many of you are coming to Switzerland later this year, let me
>>>> explain you an interesting facet of Swiss law.  In Switzerland,
>>>> downloads are legal.  We can legally download movies, musics, or in this
>>>> case books, that someone puts online.  It does not matter if the
>>>> publication itself was legal.  The pure act of downloading a copyrighted
>>>> work is legal here.
>>>>
>>>> Of course, publishing of such work is prohibited.  But we are allowed to
>>>> shared content of any matter with friends and family.
>>>>
>>>> What is the conclusion?  I have now legally obtained an electronic copy
>>>> of a book I already bought four or five times in print (for myself, my
>>>> company, for friends etc.) and I admit that this comes in as a handy
>>>> reference for my personal use.  I have no intent to circulate this file,
>>>> of course, and if there was an electronic version on sale, I would long
>>>> have bought it.
>>>>
>>>> So, distasteful or not, in some legislations, downloading the file in
>>>> question is perfectly legal.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>>
>
>

Peter Hickman | 1 Aug 2011 10:49
Gravatar

Re: n-queens -> save the solutions

Alternatively store the results on line 14 as

solutions[#solutions+1] = char

and display the results as

for s=1,#solutions do
   print(solutions[s])
end


Gmane