404 posts
Location
St. Petersburg
Posted 25 February 2013 - 06:48 AM
i know that the string API functions are in the default string metatable (or at least partially)
local str = "test"
str:len() == 4 --> true
str:sub(1,1) == "t" --> true
str:find("e") == 2 --> true
and this makes string manipulation a lot easier
my request is that the rest of the string API functions be added to the string metatable, the table API functions be added to the table metatable, and the coroutine API functions be added to the coroutine metatable
2447 posts
Posted 25 February 2013 - 06:55 AM
What? Please run that by me again. How would this be useful?
404 posts
Location
St. Petersburg
Posted 25 February 2013 - 07:00 AM
its OOP
instead of table.insert(t,"something")
it would be t:insert("something")
instead of string.match(s,"%p")
it would be s:match("%p")
instead of coroutine.resume(c,…)
it would be c:resume(…)
2447 posts
Posted 25 February 2013 - 07:06 AM
Yeah, I don't see the point. We're not going to fiddle about with default Lua stuffs' metatables. The Lua functions have the advantage of being the same across the programs/interpreters you use. String table already works like that.
88 posts
Location
UK
Posted 25 February 2013 - 07:26 AM
That's not possible for tables, since you end up overwriting the methods with your keys.
404 posts
Location
St. Petersburg
Posted 25 February 2013 - 09:47 AM
That's not possible for tables, since you end up overwriting the methods with your keys.
its the metatable, not the table itself
so yes. you could. but that wouldnt help you at all
88 posts
Location
UK
Posted 25 February 2013 - 10:49 AM
That's not possible for tables, since you end up overwriting the methods with your keys.
its the metatable, not the table itself
so yes. you could. but that wouldnt help you at all
Ok, take this example:
local openDoorFor = {
Eric = true,
Notch = true
}
if openDoorFor[somePlayerName] then
-- ...
end
Ok, so what if `somePlayerName` is 'insert' or 'remove'. This is why raw tables cannot themselves have metatables.
7508 posts
Location
Australia
Posted 25 February 2013 - 03:09 PM
instead of string.match(s,"%p") it would be s:match("%p")
Idk what you're doing wrong somewhere, but I have not come across a Lua string function that you cannot use colon notation instead of dot notation; except for functions that are not modifying or accessing a string; obviously there is no point to having string.char, which expects a number, and string.dump, which expects a function, being able to use the colon notation; I should point out that you can still use colon notation on it, it just errors those functions because you are passing the functions a string when they want a number or function.
all these workif its string.<func>(<the string>, <other-params>) then you can do it with : because of the first 'self' parameter.
404 posts
Location
St. Petersburg
Posted 25 February 2013 - 06:26 PM
–snip–
Ok, so what if `somePlayerName` is 'insert' or 'remove'. This is why raw tables cannot themselves have metatables.
they can have metatables. its just that if you set the index "insert" for a table, you cant use that method on the table anymore
997 posts
Location
Wellington, New Zealand
Posted 26 February 2013 - 12:42 AM
–snip–
Ok, so what if `somePlayerName` is 'insert' or 'remove'. This is why raw tables cannot themselves have metatables.
they can have metatables. its just that if you set the index "insert" for a table, you cant use that method on the table anymore
They can't have metatables
by default. You're welcome to set your own by calling setmetatable.
Also,
I'm not changing the behaviour of stock lua librarys
524 posts
Location
Cambridge, England
Posted 26 February 2013 - 12:45 AM
I'm not changing the behaviour of stock lua librarys
497 posts
Location
The Big Apple, NY
Posted 26 February 2013 - 12:53 AM
Immbis u quoted from the future….woah
2447 posts
Posted 26 February 2013 - 04:09 AM
No point to having this open now :)/>