User Tools

Site Tools


addons:using_libs:common

common.lua

The common library is a simple Lua file that includes other libraries that are the most often used in addons. This is a simple way for addons to include most of the other libraries in a single go rather than cluttering the top of their file with a bunch of require statements.

The common library also includes a helpful 'switch' function to mimic C++ style switch statements within Lua.

An example usage of the switch case function:

function get_container_name(id)
    return switch(tostring(id)) : caseof
    {
        ['0'] = function() return 'Inventory'; end
        ['1'] = function() return 'Mog Safe'; end,
        ['2'] = function() return 'Storage'; end,
        ['default'] = function() return nil; end,
    };
end
 
-- This should print 'Mog Safe'..
print(get_container_name(1));

addons/using_libs/common.txt · Last modified: 2017/04/23 00:36 by atom0s