lua-users home
lua-l archive

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


Hi Dirk !

I will just use Sean Conner's dump_value function. inspect doent't indent properly.

best regards.


On Thu, Apr 11, 2019 at 1:12 PM Dirk Laurie <dirk.laurie@gmail.com> wrote:
I get under Lua 5.3.5:
> inspect._VERSION
inspect.lua 3.1.0
> inspect(fin)
{ <1>{ "hello", "world" }, { <table 1>, <table 1> } }

So maybe a simple fix is to downgrade your brand-new inspect to v3.1.0?

Op Do. 11 Apr. 2019 om 10:21 het joy mondal
<joykrishnamondal@gmail.com> geskryf:
>
> Hi Sean !
>
> I am really sorry, its a inspect related issue. Not a LPEG issue.
>
> https://luarocks.org/modules/kikito/inspect
>
> I am using the most downloaded luarocks module for inspecting tables.
>
> If you do this :
>
> local inspect = require ('inspect')
>
> local constant = {'hello', 'world'}
>
> local fin = {constant, {constant, constant}}
>
> print(inspect(fin))
>
> You get :
>
> {
>   {"hello", "world"},
>   {nil, nil }
> }
>
> I will try to figure out if its an actual issue or if I am mistaken how inspect works.
>
> Cheers and Thanks !
>
> Joy
>
>
> On Thu, Apr 11, 2019 at 11:13 AM Sean Conner <sean@conman.org> wrote:
>>
>> It was thus said that the Great joy mondal once stated:
>> > Hi Everybody and Sean !
>>
>>   Hi.
>>
>> > I noticed something odd ( I am following the design decisions I have
>> > previously learnt from Sean Conner).
>> >
>> > When using lpeg.Cc with lpeg.Cmt, for whatever reason if you create a
>> > object with lpeg.Cc expect the object to be
>> >
>> > deleted or garbage collected by lpeg internals.
>> >
>> > Here is a concrete simplified example:
>> >
>> > local fin = { }
>> > local add = function(all, pos, constant)
>> >   table.insert(fin, constant)
>> >   print(fin)
>> >   return pos
>> > end
>> > local test_constant = { 'hello',  'world'}
>> >
>> > local gram = Cmt (((Cc(test_constant)) * P('a')), add)
>> >
>> > local patt = gram ^ 1
>> >
>> > return patt:match('aa')
>> >
>> > ------<| CONSOLE OUTPUT START |>--------
>> >
>> > {
>> >   {"hello", "world"}
>> > }
>> > {
>> >   {"hello", "world"}, nil -- nil should be {"hello", "world"}, why is the
>> > constant being garbage collected.
>> > }
>> >
>> > ------<| CONSOLE OUTPUT END |>--------
>>
>>   It's hard to say what you were expecting, so I ran the code using Lua
>> 5.3.4 and LPEG 1.0.2.  I modifed the code to include LPEG and to dump the
>> fin table instead of just returning the results of patt:match() (which will
>> be 3 by the way), and I got:
>>
>>         table: 0x8eaf940
>>         table: 0x8eaf940
>>         fin =
>>         {
>>           [1] =
>>           {
>>             [1] = "hello",
>>             [2] = "world",
>>           },
>>           [2] = fin.[1],
>>         }
>>
>> The first two lines are from add(), and the rest are the result of a custom
>> table dump routine I've written
>> (https://github.com/spc476/lua-conmanorg/blob/master/lua/table.lua#L131).
>> You can see that the table fin contains two references to test_constant.
>>
>> > In situations like this are we expected to assume the object created with
>> > lpeg.Cc will be deleted and make copies ? Or is my usage of Cmt with Cc
>> > unjustified ?
>>
>>   I also ran the code with Lua 5.1.5/LPEG 0.12 and Lua 5.2.4/LPEG 1.0.0 and
>> got the results shown above.
>>
>>   I can't say unjustified, but something weird is going on with your code.
>>
>>   -spc (I'm only reporting what I'm seeing ... )
>>
>>