[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Expanding the standard library functions?
- From: "Soni L." <fakedme@...>
- Date: Sun, 24 Jan 2016 17:04:58 -0200
On 24/01/16 04:58 PM, 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
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)
table.concat? or do you want a table.addall? (e.g. `table.move(from, 0,
#from, #to+1, to)`)
- 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.
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
--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.