Module ExpGamingLib

Adds some common functions used though out all ExpGaming modules

Info:

  • License: https://github.com/explosivegaming/scenario/blob/master/LICENSE
  • Author: Cooldude2606

Functions

unpack_to_G (tbl) Loads a table into _G even when sandboxed; will not overwrite values or append to tables; will not work during runtime to avoid desyncs
get_env () Used to get the current ENV with all _G keys removed; useful when saving function to global
add_metatable (tbl[, callback=tostring[, string=table.tostring]]) Creats a table that will act like a string and a function
is_type (v[, test_type=nil]) Compear types faster for faster valadation of prams
player_return (rtn[, colour=defines.colour.white[, player=game.player]]) Will return a value of any type to the player/server console, allows colour for in-game players
tick_to_hour (tick) Convert ticks to hours
tick_to_min (tick) Convert ticks to minutes
tick_to_display_format (tick) Converts a tick into a clean format for end user
gui_tree (root) Used as a way to view the structure of a gui, used for debuging

Class table

table.val_to_str (v) Returns a value in a form able to be read as a value, any value to string
table.key_to_str (k) Returns a value in a form able to be read as a key, any key to string
table.tostring (tbl) Returns a table in a form able to be read as a table
table.json (lua_table) Simmilar to table.tostring but converts a lua table to a json one
table.autokey (tbl, str) Returns the closest match to a key
table.alphanumsort (tbl) Returns the list is a sorted way that would be expected by people (this is by key)
table.keysort (tbl) Returns the list is a sorted way that would be expected by people (this is by key) (faster alterative than above)


Functions

unpack_to_G (tbl)
Loads a table into _G even when sandboxed; will not overwrite values or append to tables; will not work during runtime to avoid desyncs

Parameters:

  • tbl table table to be unpacked

Usage:

    unpack_to_G{key1='foo',key2='bar'}
get_env ()
Used to get the current ENV with all _G keys removed; useful when saving function to global

Returns:

    table the env table with _G keys removed

Usage:

    get_env() returns current ENV with _G keys removed
add_metatable (tbl[, callback=tostring[, string=table.tostring]])
Creats a table that will act like a string and a function

Parameters:

  • tbl table the table that will have its metatable set
  • callback function the function that will be used for the call (default tostring)
  • string function or string a function that resolves to a string or a string (default table.tostring)

Returns:

    table the new table with its metatable set

Usage:

    add_metatable({},function) -- returns table
is_type (v[, test_type=nil])
Compear types faster for faster valadation of prams

Parameters:

  • v the value to be tested
  • test_type string the type to test for if not given then it tests for nil (default nil)

Returns:

    bolean is v of type test_type

Usage:

  • is_type('foo','string') -- return true
  • is_type('foo') -- return false
player_return (rtn[, colour=defines.colour.white[, player=game.player]])
Will return a value of any type to the player/server console, allows colour for in-game players

Parameters:

  • rtn any value of any type that will be returned to the player or console
  • colour defines.color or string the colour of the text for the player, ingroned when printing to console (default defines.colour.white)
  • player LuaPlayer the player that return will go to, if no game.player then returns to server (default game.player)

Usage:

  • player_return('Hello, World!') -- returns 'Hello, World!' to game.player or server console
  • player_return('Hello, World!','green') -- returns 'Hello, World!' to game.player with colour green or server console
  • player_return('Hello, World!',nil,player) -- returns 'Hello, World!' to the given player
tick_to_hour (tick)
Convert ticks to hours

Parameters:

  • tick number tick to convert to hours

Returns:

    number the number of whole hours from this tick

Usage:

    tick_to_hour(216001) -- return 1
tick_to_min (tick)
Convert ticks to minutes

Parameters:

  • tick number tick to convert to minutes

Returns:

    number the number of whole minutes from this tick

Usage:

    tick_to_hour(3601) -- return 1
tick_to_display_format (tick)
Converts a tick into a clean format for end user

Parameters:

  • tick number the tick to convert

Returns:

    string the formated string

Usage:

  • tick_to_display_format(3600) -- return '1.00 M'
  • tick_to_display_format(234000) -- return '1 H 5 M'
gui_tree (root)
Used as a way to view the structure of a gui, used for debuging

Parameters:

  • root LuaGuiElement the root to start the tree from

Returns:

    table the table that describes the gui

Usage:

    Gui_tree(root) returns all children of gui recusivly

Class table

Extents the table class
table.val_to_str (v)
Returns a value in a form able to be read as a value, any value to string

Parameters:

  • v value to convert

Returns:

    string the converted value

Usage:

    table.val_to_str{a='foo'} -- return '"foo"'
table.key_to_str (k)
Returns a value in a form able to be read as a key, any key to string

Parameters:

  • k key to convert

Returns:

    string the converted key

Usage:

    table.val_to_str{a='foo'} -- return '["a"]'
table.tostring (tbl)
Returns a table in a form able to be read as a table

Parameters:

  • tbl table table to convert

Returns:

    string the converted table

Usage:

    table.tostring{k1='foo',k2='bar'} -- return '{["k1"]="foo",["k2"]="bar"}'
table.json (lua_table)
Simmilar to table.tostring but converts a lua table to a json one

Parameters:

  • lua_table table the table to convert

Returns:

    string the table in a json format

Usage:

    talbe.json{k1='foo',k2='bar'} -- return '{"k1":"foo","k2":"bar"}'
table.autokey (tbl, str)
Returns the closest match to a key

Parameters:

  • tbl table the table that will be searched
  • str string the string that will be looked for in the keys

Usage:

    table.autokey({foo=1,bar=2},'f') -- return 1
table.alphanumsort (tbl)
Returns the list is a sorted way that would be expected by people (this is by key)

Parameters:

  • tbl table the table to be sorted

Returns:

    table the sorted table

Usage:

    tbl = table.alphanumsort(tbl)
table.keysort (tbl)
Returns the list is a sorted way that would be expected by people (this is by key) (faster alterative than above)

Parameters:

  • tbl table the table to be sorted

Returns:

    table the sorted table

Usage:

    tbl = table.alphanumsort(tbl)
generated by LDoc 1.4.6 Last updated 2018-06-07 12:58:23