Common Helpers Functions

Here are all general purpose helpers functions defined in the Helpers library.

  • HL.CutBetweenLimits(txt, sLimit, eLimit, tags)
  • HL.CutStringLeft(text, maxLen)
  • HL.CutStringRight(text, maxLen)
  • HL.GetBetweenLimits(txt, sLimit, eLimit)
  • HL.GetRndColor(alpha)
  • HL.GetRndName()
  • HL.IsNil(value) (Obsolete)
  • HL.IsNotNil(value) (Obsolete)
  • HL.ParseRunArgs(CaseSensitive)
  • HL.Safe(value) (Obsolete)
  • HL.SizeString(txt, size)
  • HL.Value2Perc(Range, Value)
  • HL.WaitForAction(key, delay, callback, timeout, timeout_callback, userdata)


HL.CutBetweenLimits(txt, sLimit, eLimit, tags)

HL.CutBetweenLimits(txt, sLimit, eLimit, tags)

Removes all text between the given limiter strings, limiter included.

INPUT

  • txt : Text to process
  • sLimit : Starting limiter string
  • eLimit : Ending limiter string
  • tags : Where to add removed text (optional)

OUTPUT

  • text : Processed text
  • removed : A table with all removed strings, if the 'tags' table has been provided the strings will be added to it otherwise a new table will be returned. Each entry is a string composed by the starting limiter, the text between and and ending limiter.


HL.CutStringLeft(text, maxLen)

cutted = HL.CutStringLeft(text, maxLen)

Cut the given 'text' to the left if the string length is greater the 'maxLen' and add a triple point prefix (…) the string to indicate that the string has been shortened.

INPUT

  • text : The text to process
  • maxLen : The max length the text should have excluding the triple point

OUTPUT

  • cutted : The processed text


HL.CutStringRight(text, maxLen)

cutted = HL.CutStringRight(text, maxLen)

Cut the given string to the right if the string length is greater the <maxLen> and add the triple point (…) suffix to indicate that the string has been shortened.

INPUT

  • text : The text to process
  • maxLen : The max length the text should have excluding the triple point

OUTPUT

  • cutted : The processed text


HL.GetBetweenLimits(txt, sLimit, eLimit)

HL.GetBetweenLimits(txt, sLimit, eLimit)

Get the text between the limiters.

INPUT

  • txt : Text to process
  • sLimit : Starting limiter string
  • eLimit : Ending limiter string

OUTPUT

  • ttext : Results table, each entry is a string composed by the starting limiter, the text between and and ending limiter.


HL.GetRndColor(alpha)

color = HL.GetRndColor(alpha)

Returns a random color, eventually with a random alpha transparency value.

INPUT

  • alpha : Set to TRUE if you want to get a random color with random transparency.


HL.GetRndName()

name = HL.GetRndName()

Use this function to obtain a unique random name anytime you need it.

OUTPUT

  • name : A string with an unique random name.

NOTES
All returned random names are stored in the HL.RandomNames table to avoid reusing and make them unique, if you wish to reset the assigned names for some reasons (for example for low memory conditions) just reset this table but be aware that already assigned names could be reused.



HL.IsNil(value)

result = HL.IsNil(value)

OBSOLETE : Use native IsNil() instead.

Check 'value' and returns TRUE if it is NIL, otherwise returns FALSE.

INPUT

  • value : Value to check against NIL.

OUTPUT

  • result : TRUE if 'value' is NIL otherwise FALSE.


HL.IsNotNil(value)

result = HL.IsNotNil(value)

OBSOLETE : Use Not(IsNil()) instead

Check 'value' and returns FALSE if it is NIL, otherwise returns TRUE

INPUT

  • value : Value to check against NIL.

OUTPUT

  • result : FALSE if 'value' is NIL otherwise TRUE.


HL.ParseRunArgs(CaseSensitive)

parsedArgs = HL.ParseRunArgs(caseSensitive)

Parse command line arguments and return a table indexed with the argument key and with the value sets with the argument's parameter. The switch 'caseSensitive' defaults to TRUE, set it to FALSE to parse arguments and parameters without case distinctions.

INPUT

  • caseSensitive : TRUE to parse case sensitive arguments and parameters.

OUTPUT

  • parsedArgs : A table indexed with the command line arguments and with values sets as the parameter values.

NOTE
Keep in mind that all value will be returned as strings, it's up to you to convert values in the needed format. If 'caseSensitive' is TRUE all arguments will be lowercase. This command is really usefull to test argument passed with the command line simply testing the resulting table keys.



HL.Safe(value)

result = HL.Safe(value)

OBSOLETE : Use ToString() instead

Returns the string 'NIL' if 'value' is NIL, otherwise returns 'value' without any changes. This function is usefull to concatenate strings without worring about errors caused by concatenating uninitialized variables.

INPUT

  • value : Value to process.

OUTPUT

  • result : 'value' or the string 'NIL'


HL.SizeString(txt, size)

processed = HL.SizeString(txt, size)

This function is usefull to process strings and to produce easily aligned text columns, the string 'txt' will be processed and adapted to the 'size' length by adding spaces or by removing exceeding characters and adding '…' to the end to indicate that the string is not finished.

INPUT

  • txt : Text to process.
  • size : Text length including the triple dots (if needed) or the additional spaces.

OUTPUT

  • processed : Processed text with the exact length equal to 'size'.


HL.Value2Perc(Range, Value)

percentual = HL.Value2Perc(range, value)

Convert the given 'value' to a percentual value, the percentual will be calculated using the table 'range' that must have the following fields:
→ [0] : Minimum value in the range → [1] : Maximum value in the range If 'value' is out of range it will get Minimum or Maximum depending on the boundary it exceeds.

INPUT

  • range : A table with at least two entries at index 0 and 1:
    → [0] : Lower range limit
    → [1] : Higher range limit
  • value : Value we need to convert into a percentual notation.

OUTPUT

  • percentual : Converted value ranging from 0 to 1.


HL.WaitForAction(key, delay, callback, timeout, timeout_callback, userdata)

HL.WaitForAction(key, delay, callback, timeout, to_callback, userData)

This function is used to wait for an user action, the action can be a key press defined by 'key', the left mouse button press or any button of any connected joystick. It's possible to define a timeout to let the program continue without user action. This routine provides callback functions to run an animation or to accomplish other tasks during the wait or to call a specific function if the timeout occurs.

INPUT

  • key : Monitored key.
  • delay : Delay in milliseconds for the detection loop, every wait a call to 'callback' will be made.
  • callback : Function called every loop check with the 'userData' parameter. If the callback function returns TRUE the wait loop will be interrupted immediatly.
  • timeout : Timeout in milliseconds.
  • to_callback : Function called if the timeout is reached, the function will be called with 'userData' parameter.
  • userData : Custom user data parameter passed to the callback function.

OUTPUT

  • result : False if a timeout occurred, otherwise True
hollywoodlibs/helpers/common.txt · Ultima modifica: 2016/10/11 18:49 da admin
CC Attribution-Noncommercial 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0