Over a year ago I made a library extension module. It kind of sucks though, now that I looked back on it and it was just me being silly and not taking it seriously at all. Please don’t use that one.
It’s been over a year, and why not make a sequel to this thing. This one is much much much much better, objectively.
Changes
So a few changes have been made:
Structural improvements (libraries are their own module, its members are also in their own modules)
Rewritten completely to use Luau type annotations as well as improvements to code itself
Clutter removed
It is now on GitHub, with its own page for documentation
Niche functions moved to custom libraries (e.g string.digitalformat → format.digital_format)
Removed any functions Roblox has added, like CFrame.lookAt and table.clear.
While a few things have been removed I believe all the benefits of the changes outweigh the removal of those functions that were clutter/useless anyway. There are some new additions though, just as not as many as removals.
This module is licensed under the MIT License. So this means that you can fork the module for public/private use and use it commercially, however you must preserve the copyright and license notice when doing this.
Contributions
Pull requests are welcome, but when contributing please respect the style guide found in CONTRIBUTING.md or reply below with your contribution, still respecting the style guide.
Also maybe an nroot function? A simple definition would be very similar to math.cbrt except you would need to check if the root is even.
local function nroot(x, root)
local value = math.abs(x) ^ (1 / root)
if ((x < 0) and (root % 2 == 0)) then
return nil
end
return math.sign(x) * value
end
Sometimes you just wish things like this are already in roblox, such as table.shuffle and table.reverse. Amazing library though! I wonder if roblox will ever add some of these.
a table.map would be nice too. I don’t think there is one in Libraries++ or Roblox though.
There is a table.foreach but if I remember it is deprecated for some reason?
While we’re at it, table.filter and table.reduce would also be nice.
table.foreach and table.foreachi is depcreated in Lua 5.1 (it should’ve been deprecated in Lua 4.0), because it seems like it’s been replaced by the for loop in Lua 4.0
I don’t think Roblox will likely to add table.map, table.filter, etc. IIRC someone said that it’ll be slower as every function call will go through the C → Lua(u) boundary.
Just wanted to announce some more updates on this module:
Additions
Added color3 library
Added color3.add(lhs: Color3, rhs: Color3): Color3, should be self-explanatory. Adds 2 Color3s and returns the sum of that, since Roblox doesn’t implement __add for Color3s.
Added color3.subtract(lhs: Color3, rhs: Color3): Color3, should be self-explanatory. Subtracts 2 Color3s and returns the difference of that, since Roblox doesn’t implement __sub for Color3s.
Added color3.multiply(lhs: Color3, rhs: Color3 | number): Color3, should be self-explanatory. Multiplies 2 Color3s (or Color3 by number) and returns the product of that, since Roblox doesn’t implement __mul for Color3s.
Added color3.divide(lhs: Color3, rhs: Color3 | number): Color3, should be self-explanatory. Divides 2 Color3s (or Color3 by number) and returns the quotient of that, since Roblox doesn’t implement __div for Color3s.
Added instance library
Added get_ancestors(instance: Instance): { Instance? }, which gets all the ancestors of a given instance.
Added get_ancestors_of_class(instance: Instance, class_name: string): { Instance? }, which functions like instance.get_ancestors but only gets ancestors of a given class.
Added get_ancestors_which_are_a(instance: Instance, class_name: string): { Instance? }, which functions like instance.get_ancestors_of_class except it takes into account inheritance.
Added get_children_of_class(instance: Instance, class_name: string): { Instance? }, which functions like Instance:GetChildren() but only gets children of a certain class.
Added get_children_which_are_a(instance: Instance, class_name: string): { Instance? }, which functions like instance.get_children_of_class except it takes into account inheritance.
Added get_descendants_of_class(instance: Instance, class_name: string): { Instance? }, which functions like Instance:GetDescendants() but only gets descendants of a certain class.
Added get_children_which_are_a(instance: Instance, class_name: string): { Instance? }, which functions like instance.get_descendants_of_class except it takes into account inheritance.
Added get_siblings(instance: Instance): { Instance? }, which gets the siblings of an instance.
Added get_siblings_of_class(instance: Instance, class_name: string): { Instance? }, which functions like instance.get_siblings but only gets siblings of a certain class.
Added get_siblings_which_are_a(instance: Instance, class_name: string): { Instance? }, which functions like instance.get_siblings_of_class except it takes into account inheritance.
Added wait_for_child_of_class(instance: Instance, class_name: string): Instance?, which waits for a child of the given class. Does not have a timeout parameter, though feel free to make a PR for this.
Added wait_for_child_which_is_a(instance: Instance, class_name: string): Instance?, which functions like instance.wait_for_child_of_class except it takes into account inheritance. Does not have a timeout parameter, though feel free to make a PR for this.
Changes
Changed array type syntax { [number]: T } to { T } throughout the source since the parser of the linter I use didn’t support the latter until recently.
Documentation will be updated soon documentation has been updated
Just wanted to announce some more updates on this module:
Additions:
Documented instance
Documented color3
Added misc
Added misc.spawn(f, ...), a “fast spawn” implementation that uses bindable events to mitigate the ~1/30th of a second you yield with the stock spawn function. Passes arguments ... to f.
Added misc.wait(num: number): number, an alternative to Roblox’s stock wait function that uses RunService.Heartbeat.
Added misc.delay(num: number, f: (number?) -> ()), an alternative to Roblox’s stock delay that uses the above functions.
Should hopefully make it easier for some, since not everyone might (want to) use a file synching tool like rojo to sync the code over into their game from their file system.
The source was originally just on github, so you’d have to import them by hand or use a plugin like RepoToRoblox (which you should totally buy if you haven’t already), or the preferred method, which is using rojo to sync them into your game. Which is kind of how you were meant to do it in the first place. The goal of uploading this to the library is to make it a bit more accessible, since the majority of developers have everything in Roblox studio
Sorry for necro, I have no honest clue what I am doing wrong, but for some reason, I can’t get this to work. First, comb has an infinite wait for script.Parent.math, and when I move the module out, the code stops yielding. Second, when I call a function listed in the documentation page, it says attempt to call nil value.