lua-users home
lua-l archive

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


Penlight is the solution for me. It's really very simple to use and
supports a large number of nice features. Let's my first test:

class = require('pl.class')
dir = require('pl.dir')

class.folder(class.properties)

function folder:_init(name)
filter = '*'
self.name = name
end

function folder:get_count()
local items = dir.getfiles(self.name, filter)
return #items
end

function folder:set_filter(pattern)
filter = pattern
end

folder = folder('c:/fontes')
print(folder.count)
folder.filter = '*.exe'
print(folder.count)

Thank you for the indication. I really liked Penlight.

I hope the posting is correct. I am blind, I use screen reader. In the
Gmail page, there are several "reply" buttons. It's sometimes
difficulty to understand where the message will be. I used to access
by means of "alt+shift+r" and I don't know if this changes something.


2012/6/28, Henk Boom <henk@henk.ca>:
> On 28 June 2012 09:29, luciano de souza <luchyanus@gmail.com> wrote:
>> Hello all,
>>
>> I wasn't acquainted with OOP strategies in Lua. What I know is that we
>> have nice options like Classlib, Loop, LOS... and the raw handling of
>> metatables.
>>
>> Supppose the following structure:
>>
>> -- [[
>> class number
>> method GetValue
>> property value
>> ]] --
>>
>> Now suppose the following function:
>>
>> function number:GetValue()
>> return math.random(100)
>> end
>>
>> I would like to do something like that:
>>
>> number = number()
>> print(number.value)
>>
>> The reply could be 80, 35, 44 or any randomic value between 0 and 100.
>>
>> Using Classlib, LOOP or any other Lua library with OOP support, how
>> can I do this?
>
> Steve Donovan's Penlight library has a class implementation, and if
> you inherit from class.properties it will set up the metatable so that
> get_* and set_* are automatically called. It does have the unfortunate
> side effect that getters are automatically set up for variables
> starting with an underscore, which I find problematic because I often
> use _variables as pseudo-private fields.
>
> https://github.com/stevedonovan/Penlight/blob/master/lua/pl/class.lua#L151
>
>     henk
>
>