lua-users home
lua-l archive

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


On 08/01/2010 18:49, Luiz Henrique de Figueiredo wrote:


All feedback welcome. Thanks.
--lhf



1) __len metamethod is allowed to return anything besides numbers.

local array = {1,2,3,4,5}
setmetatable(array, { __len = function() return "hi there" end })
local length = 20 + #array -- attempt to perform arithmetic on a string value

Checking each time that the result is a number may be expensive. Perhaps adding an api_check ?

2) package.searchpath
I once requested a way for required package to know where they were found. I thought that this might be possible using package.searchpath but it doesn't.

Say I have a package called "foo.bar" (that is, the file "bar.lua" in the directory "foo")
It is accessible in the path, so require "foo.bar" works.
But in foo\bar.lua, this won't work.

print(package.searchpath((...))) -- gives an error, looks for "foo.bar" instead of "foo\\bar"

Is it possible for searchpath to deal with package names also? I could do that in Lua, but I will be rewriting what the Lua loader is doing.


Regards,
Ignacio