|
|
|
|
|
by wahern
3620 days ago
|
|
String trim is just: foo:gsub("%s*$", "")
or foo:gsub("^%s*", "")
The standard idiom for OOP in Lua is a one-liner: return setmetatable(self, mt)
where mt.__index has all the methods. How you assign to mt.__index can vary across modules according to style, but that's a _purely_ asethetic issue. The mechanics are identical. Using a module to accomplish it creates a useless dependency.There are many criticisms one could make of Lua, but I don't think those two particular criticisms are legit. They're classic bikeshedding. |
|
See, its not that simple :) http://lua-users.org/wiki/StringTrim
Anyway, I wasn't trying to say bad things about Lua with my examples. Its just that if you go to any large Lua project out there there is a very good chance you will find some "utils" module in there with yet another reimplementation of a lot of these common functions. Ideally we should have people reusing more stuff from Luarocks than they are right now.