lua-users home
lua-l archive

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




On 23/06/15 04:31 PM, Sean Conner wrote:
It was thus said that the Great Soni L. once stated:
On 23/06/15 03:57 PM, Sean Conner wrote:
On Tue, Jun 23, 2015 at 2:11 PM, Soni L. <fakedme@gmail.com> wrote:
__call and co() makes it look like a function call, which may be kinda
confusing. On the other hand OOP syntax co:resume() is more Lua-like, as
strings have it too. You also cannot index functions.
   Yes you can.

	function foo(x)
	  return 3 * x + 5
	end

	mt =
	{
	  __index = function(obj,idx)
	    local d = string.dump(obj)
	    return d:sub(idx,idx)
	  end
	}
	
	debug.setmetatable(foo,mt)
Try it without debug.
	lua_getglobal(L,"foo");
	lua_getglobal(L,"mt");
	lua_setmetatable(L,-2);

   -spc


...

File handles can use oop syntax;
Strings can use oop syntax (only thing you don't call a library function to create that has a metatable); So why can't threads? They're like file handles, as in you call a library function to create them. This would just increase consistency a bit. (another option would be to make it so file handles don't have a metatable and you have to call io.write(fd, ...) and such instead)

(I can't think of anything else that would feel "better" with metatables... adding metatables to numbers (with __index being `math`) would be just weird: n:tointeger(), n:pow(0.5), etc (mostly because they're, y'know, _math_ functions. if we had a `number` library then /maybe/ I'd be ok with it.))

--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.