[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN]lstore 0.1.0, a Lua JSON document store
- From: Pierre-Yves Gérardy <pygy79@...>
- Date: Fri, 3 Feb 2012 11:18:37 +0100
On Fri, Feb 3, 2012 at 10:02, Fabien Bourgeois <fbourgeois@yaltik.com> wrote:
> Le 02/02/2012 20:23, Pierre-Yves Gérardy a écrit :
> I've refactored with local but I've used to try this solution before and
> I've had a problem with it. Stop me if I'm wrong :
>
> with `new_db:_dbpath(path, ext)`, self is passed as first parameter.
> However, in the context of `open` method, self is lstore, not the new_db
> object. Thus, methods will operate on the global lstore, am I wrong ?
Nope, the column notation is just syntactic sugar.
function ``a:b(...) end` becomes ``function a.b(self,...) end``.
``a:b()`` is translated to ``a.b(a)``. The only difference is that the
interpreter saves a variable lookup in the first case.
Try this if you want to see what happens behind the scenes:
```
obj = {c = function (self, ...) print( "method", self, ... )end}
a = setmetatable( {}, {__index = function (tbl,key)
print( "index", tbl, key )
return obj
end
})
a.b:c( "grapefruit" )
a.b.c( a.b, "pineapple" )
```
-- Pierre-Yves
- References:
- [ANN]lstore 0.1.0, a Lua JSON document store, Fabien Bourgeois
- Re: [ANN]lstore 0.1.0, a Lua JSON document store, Pierre-Yves Gérardy
- Re: [ANN]lstore 0.1.0, a Lua JSON document store, Fabien Bourgeois
- Re: [ANN]lstore 0.1.0, a Lua JSON document store, Pierre-Yves Gérardy
- Re: [ANN]lstore 0.1.0, a Lua JSON document store, Fabien Bourgeois