[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: qOOP - Quick Object Oriented Programming
- From: Dirk Laurie <dirk.laurie@...>
- Date: Fri, 30 Mar 2012 13:27:02 +0200
> I've posted it on Pastebin...so that everybody can see the source code easily...
> Link: http://pastebin.com/SM7bmWk2
>
~~~
-- Searches a method in a list of tables. This will be the core
-- of multiple inheritance featur-- Searches an item in a table.
-- Returns true on success, plus the key, otherwise false.
local function table_find(item,table)
for k in pairs(table) do
if table[k] == item then return true,k end
end
return false
end
~~~
It's more idiomatic to return `nil` if the item is not in the table
and otherwise
return the key.
~~~
-- Searches a method in a list of tables. This will be the core
-- of multiple inheritance feature implementation
local function call_method(method,...)
for k in ipairs(arg) do
local m = arg[k][method]
if m and type(m)=='function' then return m end
end
return nil
end
~~~
This differs from PiL 16.3 mainly in the type test. I don't see
the point of allowing users to shadow a superclass method
with something that is not a function. It seems to be an open
invitation to write buggy programs. If you don't test, and `m`
is not callable, at least there will be an error later.