img



img

Lib:fun


By: _ForgeUser22512980
Addon | img 296




Description

___________________________________________________________________________________________________________________________

Functional Lua for Wildstar


Overview


Lib:fun is a port of Roman Tsisyk's Functional Lua library to Wildstar. It enables the use of many common functions found in functional programming languages within Wildstar addons, such as mapfilter, and reduce.

Fun is a small wrapper addon that provides an alternate method of access by wrapping all the functions into the Fun table and making it globally accessible. This may be desirable for use with /eval, the GeminiConsole in-game REPL, or for early addon development that uses lib:fun. This avoids needing to load the lib manually in GeminiConsole, which helps with in-game testing and early development. If it proves useful for the addon, lib:fun can then be included in the addon itself with minimal change to the code.

There is also now a second file, fun-extra, that provides my own constructs for other FP-esque things I miss. fun-extra contains the following:

  • two variations on cond: cond and gen_cond
  • a functional if called iff
  • loop, a function that works like each, but trades some flexibility for speed.


Usage

Import all using `lib:fun` in an addon:

f = Apollo.GetPackage("lib:fun").tPackage
f.each(Print, f.range(3))

Import specific functions from lib:fun in an addon:

ar = {'each', 'range'}
f = Apollo.GetPackage("lib:fun").tPackage.import(ar)
f.each(Print, f.range(3))

Using the global Fun addon (such as with GeminiConsole):

Fun.each(Print,Fun.range(3)) --- direct use
f = Fun --- binding to another name
f = Fun.import({'head', 'tail'}) --- binding specific functions from Fun

_G pollution of globals:

[BEWARE] Doing this affects all addons and is a really bad idea. It's only listed for completeness. Seriously, don't do this, especially in release code.
 

for k,v in pairs(Apollo.GetPackage("lib:fun").tPackage) do _G[k] = v end
each(Print, range(3))



About Project

Created: December 18th 2023

Updated: December 18th 2023

Project ID: 91335

License: All Rights Reserved

__________________________________________

Game Versions:

1.01.03

1.01.03

1.01.03

1.01.03

1.01.03

__________________________________________

Flavors:

WoW Retail

__________________________________________

Categories

Companions

Battle

__________________________________________

Main File

_ForgeUser22512980_Lib:fun.zip
  • Release
  • December 18th 2023

    __________________________________________

    Recent File

    _ForgeUser22512980_Lib:fun.zip
  • Release
  • December 18th 2023

    __________________________________________

    Members

    img
    _ForgeUser22512980
    Owner

    __________________________________________

    Report