[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Expanding the standard library functions?
- From: Thijs Schreijer <thijs@...>
- Date: Tue, 26 Jan 2016 07:32:51 +0000
> On Jan 24, 2016, at 10:58 AM, chuckiels2011@gmail.com wrote:
>
> Hello,
>
> I'm new to the mailing list, so let me know if I'm inadvertently doing anything wrong. If I am, sorry about that :P
By now, you must have had an interesting read of all the opinions I guess. :)
Despite all that, welcome to the community! It’s a great language even though some elements in the language as well as in the community might seem unlike other communities, over time I have become to appreciate them.
>
> I was wondering if there is a posiblity of expanding the Lua standard library (mostly the string and table library). There are a few basic utility functions that I was hoping could be added to improve usability out of the box:
>
> Strings:
> - capitalize
> - split (this one I think is much needed. I'm constently rewriting myself split functions).
> - strip (also write myself a lot of whitespace striping functions)
> - insert
>
> Tables:
> - any (the same as any? in Ruby)
> - join (same as split)
> - select (a filter function that can either accept a value or a function)
> - shuffle (can be used to get a random value too, i.e `({1,2,3}):shuffle[1]`)
>
> I was heavily inspired by Ruby's standard library, but tried to avoid adding functions that are just simple aliases. My rule was, if it can't be done in one line of Lua code, write a new function for it.
Building your own toolkit is a good way to start working with Lua. But as others pointed out, lots of stuff is already available in all the mentioned places. One of the core elements has always been that the language facilitates all different sort of paradigms and styles, but it doesn’t force you to use what you don’t want.
Do ruby style if you like, or use Penlight if you like Python style, libraries for functional types are available, and many, many class-systems exist.
What I find the most pleasant part is the flexibility of the language, that it lets me choose what paradigm to use. So I can apply the most efficient solutions to my problems.
Happy coding Lua!
Thijs
>
> I've implemented all of these functions in a patch: https://gist.github.com/fc4d1f1f7bd1d649ddd0. There's a TODO here and there, but it mostly works (the C API is awesome!).
>
> These functions would mean less boilerplate, faster code (since the standard library is implemented in C) and better readability. Let me know what you guys think :)
>
> - Charles
>
>