Lua-Quick-Try-Out Function Reference

Overview

array Functions for array manipulation or handling.
bit Functions for bit manipulation.
crc Functions for cyclic redundancy check calculations.
dia Functions for drawing curves in diagrams.
gfx Functions for 2D pixel based drawings.
math_ex Additional mathematical functions.
string_ex Functions for string manipulation.
sys Functions for system time and other.
tab Functions to view data in a table.
vgfx Functions for 2D vector drawings.

LUA functions

Table array

functions:

array.add Add a number or an other array to an array.
array.div Divide an array by a number or an other array.
array.extract Extract parts of an array.
array.make This function creates an array filled with values.
array.max Returns the maximum value.
array.min Returns the minimum value.
array.mul Multiply a number or an other array with an array.
array.print This function prints an array as a comma separated list.
array.reverse Reverse the order of the array elements.
array.sub Subtract a number or an other array from an array.
array.to_number Converts an array of strings to an array of numbers.
array.to_string Prints an array of number into a string.

Table bit

functions:

bit.and Bitwise AND operation.
bit.clear Set the bit to 0.
bit.get Returns the state of a bit.
bit.nand Bitwise NAND operation.
bit.nor Bitwise NOR operation.
bit.not Bitwise NOT operation.
bit.or Bitwise OR operation.
bit.reverse Returns the given value with reverse bit order.
bit.set Set the bit to 1.
bit.shl Shift a 32 bit value to left.
bit.shr Shift a 32 bit value to right.
bit.toggle Toggle the bit. (Change bit state 0 to 1 or bit state 1 to 0.)
bit.xnor Bitwise XNOR operation.
bit.xor Bitwise XOR operation.

Table crc

functions:

crc.crc16 This function calculates the 16 bit crc checksum.
crc.crc32 This function calculates the 32 bit crc checksum.
crc.crc8 This function calculates the 8 bit crc checksum.

properties:

crc.polynom16 The crc 16 polynom.
crc.polynom32 The crc 32 polynom.
crc.polynom8 The crc 8 polynom.

Table dia

functions:

curve:append_data Appends a data point to the curve.
curve:clear_data Clears the data of the curve.
diagram:delete Deletes the diagram.
curve:delete Removes the curve from the diagram.
dia.delete_all Deletes all diagrams.
diagram:delete_all_curves Delete all curves in the diagram.
dia.new Creates a new diagram.
diagram:new_curve Creates a new curve.
diagram:save_csv Saves the diagram as a CSV (comma seperated values, actually tabulator seperated values) file.
diagram:save_img Saves the diagram as a PNG (portable network graphic) image file.
curve:set_data Sets all curve data points.

Table gfx

functions:

gfx.begin_update Disable graphics scene update to speed up the drawing operations.
gfx.clear Clears the drawing.
gfx.draw_circle Draws a circle with the current color.
gfx.draw_ellipse Draws an ellipse with the current color.
gfx.draw_line Draws a straight line with the current color.
gfx.draw_pnt Draws a point with the current color.
gfx.draw_polygon Draws a polygon with the current color. The last point is connected with the first point.
gfx.draw_rect Draws a rectangle with the current color.
gfx.draw_text Draws text.
gfx.end_update Enable graphics scene update. (see also begin_update)
gfx.fill_circle Draws a filled circle with the current fill color.
gfx.fill_ellipse Draws an filled ellipse with the current fill color.
gfx.fill_polygon Draws a filled polygon with the current fill color. The last point is connected with the first point.
gfx.fill_rect Draws a filled rectangle with the current fill color.
gfx.save_img Saves the current drawing as a PNG (portable network graphics) image file.
gfx.set_color Changes the current color.
gfx.set_fill_color Changes the current fill color.
gfx.set_size Sets the size of the drawing area.

Table math_ex

functions:

math_ex.calc_fft Calculates the fast fourier transformation of an array with values.
math_ex.lin_reg Calculates a linear regression line for an array with points using the least square method.
math_ex.mean Calculates the mean value from a list of values.
math_ex.mean_filter Applies the mean filter to the given values. The mean filter replaces the values by the arithmetic mean of the surrounding values.
math_ex.median_filter Applies the median filter to the given values. The median filter is a nonlinear digital filtering technique, used to remove noise.

Table string_ex

functions:

string_ex.split Splits a string. The result is an array of strings.

Table sys

functions:

sys.delay Stops the program execution for the given time. The time is counted from the begin of this function call.

properties:

sys.time Returns the current system time in seconds since 1970-01-01.
sys.time_str Returns the current system time as a formatted string in the form 21:49:25 2010-06-08.

Table tab

functions:

tab.clear Clears all data.
tab.save_csv Save the values in the table as a CSV (comma seperated values, actually tabulator seperated values) file.
tab.set_column_values Writes values in a table column.
tab.set_row_values Writes values in a table row.
tab.set_size Changes the number of rows and columns.
tab.set_value Writes a value in the table.

Table vgfx

functions:

vgfx.clear Clears the drawing.
vgfx.draw_circle Draws a circle with the current color.
vgfx.draw_ellipse Draws an ellipse with the current color.
vgfx.draw_line Draws a straight line with the current color.
vgfx.draw_polygon Draws a polygon with the current color. The last point is connected with the first point.
vgfx.draw_rect Draws a rectangle with the current color.
vgfx.draw_text Draws text.
vgfx.fill_circle Draws a filled circle with the current fill color.
vgfx.fill_ellipse Draws an filled ellipse with the current fill color.
vgfx.fill_polygon Draws a filled polygon with the current fill color. The last point is connected with the first point.
vgfx.fill_rect Draws a filled rectangle with the current fill color.
vgfx.save_img Saves the current drawing as a PNG (portable network graphics) image file.
vgfx.save_svg Saves the current drawing as a SVG (scalable vector graphic) file.
vgfx.set_color Changes the current color.
vgfx.set_fill_color Changes the current fill color.

LUA functions


Table: array

Functions for array manipulation or handling.


array.add (function)
result = array.add ( array, param )
Add a number or an other array to an array.
Parameters:
array The array.
param Array or number.
Return:
result The resulting array.
Example:
  result1 = array.add( {1, 2, 3, 4, 5}, 12)
  result2 = array.add( {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5} )
      

array.div (function)
result = array.div ( array, param )
Divide an array by a number or an other array.
Parameters:
array The array.
param Array or number.
Return:
result The resulting array.
Example:
  result1 = array.div( {1, 2, 3, 4, 5}, 12)
  result2 = array.div( {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5} )
      

array.extract (function)
result = array.extract ( array, start_index, step_size, count )
Extract parts of an array.
Parameters:
array The array.
start_index The start index (1 to array length).
step_size The step size (can be negative). (This parameter is optional.)
count Maximum number of elements to be extracted. (This parameter is optional.)
Return:
result The resulting array.
Example:
  a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
  result = array.extract(5)       -- result = { 5, 6, 7, 8, 9, 10 }
  result = array.extract(2, 2)    -- result = { 2, 4, 6, 8, 10 }
  result = array.extract(2, 2, 3) -- result = { 2, 4, 6 }
  result = array.extract(5, 1, 4) -- result = { 5, 6, 7, 8 }
      

array.make (function)
array.make ( start, end, step )
This function creates an array filled with values.
Parameters:
start The first value.
end The last value.
step The step width. (This parameter is optional.)
Example:
  -- creates an array filled with the values 1, 2, 3, 4, 5
  a = array.make(1, 5)
  
  -- creates an array filled with the values 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5
  b = array.make(1, 5, 0.5)
      

array.max (function)
result = array.max ( array )
Returns the maximum value.
Parameters:
array The array.
Return:
result The maximum value.
Example:
  arr = {9, 8, 3, 4, 5}
  print("Max value: " .. array.max(arr))
      

array.min (function)
result = array.min ( array )
Returns the minimum value.
Parameters:
array The array.
Return:
result The minimum value.
Example:
  arr = {9, 8, 3, 4, 5}
  print("Min value: " .. array.min(arr))
      

array.mul (function)
result = array.mul ( array, param )
Multiply a number or an other array with an array.
Parameters:
array The array.
param Array or number.
Return:
result The resulting array.
Example:
  result1 = array.mul( {1, 2, 3, 4, 5}, 12)
  result2 = array.mul( {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5} )
      

array.print (function)
array.print ( array )
This function prints an array as a comma separated list.
Parameters:
array The array to be printed.
Example:
  a = { 1, 2, 3, 4 }
  array.print(a)
      

array.reverse (function)
result = array.reverse ( array )
Reverse the order of the array elements.
Parameters:
array The array to be reversed.
Return:
result The reversed array.
Example:
  a = { 1, 2, 3, 4 }
  r = array.reverse(a)
  array.print(r)
      

array.sub (function)
result = array.sub ( array, param )
Subtract a number or an other array from an array.
Parameters:
array The array.
param Array or number.
Return:
result The resulting array.
Example:
  result1 = array.sub( {1, 2, 3, 4, 5}, 12)
  result2 = array.sub( {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5} )
      

array.to_number (function)
number_array = array.to_number ( string_array )
Converts an array of strings to an array of numbers.
Parameters:
string_array Array of strings.
Return:
number_array Array of numbers.
Example:
  str = "1, 2, 3"
  str_arr = string_ex.split(str, ",")
  num_arr = array.to_number(str_arr)
  print(num_arr[1] + num_arr[2] + num_arr[3])
      

array.to_string (function)
string = array.to_string ( array, delimiter )
Prints an array of number into a string.
Parameters:
array The array of numbers.
delimiter The number delimiter. (Default is comma.) (This parameter is optional.)
Return:
string The array as a string
Example:
  arr = {9, 8, 3, 4, 5}
  str = array.to_string()
  print("Array as string: " .. str)
      


Table: bit

Functions for bit manipulation.


bit.and (function)
result = bit.and ( value1, value2 )
Bitwise AND operation.
Parameters:
value1 First operand.
value2 Second operand.
Return:
result The result of the operation.
Example:
  r = bit.and(a, b)
      

bit.clear (function)
result = bit.clear ( value, bit_number )
Set the bit to 0.
Parameters:
value The value.
bit_number The bit number: 0 ... 31.
Return:
result The result of the operation.
Example:
  -- clear bit number 5
  r = bit.clear(a, 5)
      

bit.get (function)
bit_state = bit.get ( value, bit_number )
Returns the state of a bit.
Parameters:
value The value.
bit_number The bit number: 0 ... 31.
Return:
bit_state The state of the bit: 0 or 1.
Example:
  -- returns the state of bit number 5
  s = bit.get(a, 5)
      

bit.nand (function)
result = bit.nand ( value1, value2 )
Bitwise NAND operation.
Parameters:
value1 First operand.
value2 Second operand.
Return:
result The result of the operation.
Example:
  r = bit.nand(a, b)
      

bit.nor (function)
result = bit.nor ( value1, value2 )
Bitwise NOR operation.
Parameters:
value1 First operand.
value2 Second operand.
Return:
result The result of the operation.
Example:
  r = bit.nor(a, b)
      

bit.not (function)
result = bit.not ( value )
Bitwise NOT operation.
Parameters:
value Operand.
Return:
result The result of the operation.
Example:
  r = bit.not(a)
      

bit.or (function)
result = bit.or ( value1, value2 )
Bitwise OR operation.
Parameters:
value1 First operand.
value2 Second operand.
Return:
result The result of the operation.
Example:
  r = bit.or(a, b)
      

bit.reverse (function)
result = bit.reverse ( value, num_bits )
Returns the given value with reverse bit order.
Parameters:
value The value.
num_bits The size of the value in bits.
Return:
result The value with reverse bit order.
Example:
  r = bit.reverse(a, 8) -- reverse the bit order of a byte (8 bit)
  r = bit.reverse(a, 16) -- reverse the bit order of a word (16 bit)
  r = bit.reverse(a, 32) -- reverse the bit order of a double word (32 bit)
      

bit.set (function)
result = bit.set ( value, bit_number )
Set the bit to 1.
Parameters:
value The value.
bit_number The bit number: 0 ... 31.
Return:
result The result of the operation.
Example:
  -- set bit number 5
  r = bit.set(a, 5)
      

bit.shl (function)
result = bit.shl ( value, num_bits )
Shift a 32 bit value to left.
Parameters:
value The value.
num_bits The number of bits the value shall be shifted.
Return:
result The result of the operation.
Example:
  r = bit.shl(a, 2) -- shift a to left by 2 bits
      

bit.shr (function)
result = bit.shr ( value, num_bits )
Shift a 32 bit value to right.
Parameters:
value The value.
num_bits The number of bits the value shall be shifted.
Return:
result The result of the operation.
Example:
  r = bit.shr(a, 2) -- shift a to right by 2 bits
      

bit.toggle (function)
result = bit.toggle ( value, bit_number )
Toggle the bit. (Change bit state 0 to 1 or bit state 1 to 0.)
Parameters:
value The value.
bit_number The bit number: 0 ... 31.
Return:
result The result of the operation.
Example:
  -- toggle bit number 5
  r = bit.toggle(a, 5)
      

bit.xnor (function)
result = bit.xnor ( value1, value2 )
Bitwise XNOR operation.
Parameters:
value1 First operand.
value2 Second operand.
Return:
result The result of the operation.
Example:
  r = bit.xnor(a, b)
      

bit.xor (function)
result = bit.xor ( value1, value2 )
Bitwise XOR operation.
Parameters:
value1 First operand.
value2 Second operand.
Return:
result The result of the operation.
Example:
  r = bit.xor(a, b)
      


Table: crc

Functions for cyclic redundancy check calculations.


crc.crc16 (function)
new_crc = crc.crc16 ( crc, data )
This function calculates the 16 bit crc checksum.
Parameters:
crc The current checksum.
data A number (one byte) or an array of bytes.
Return:
new_crc The new checksum.
Example:
  checksum = 0
  checksum = crc.crc16(checksum, 0x1545)
  checksum = crc.crc16(checksum, 4452)
  checksum = crc.crc16(checksum, { 1, 2, 3, 4, 5, 6 } )
  print(checksum)
      

crc.crc32 (function)
new_crc = crc.crc32 ( crc, data )
This function calculates the 32 bit crc checksum.
Parameters:
crc The current checksum.
data A number (one byte) or an array of bytes.
Return:
new_crc The new checksum.
Example:
  checksum = 0
  checksum = crc.crc32(checksum, 0x1549895)
  checksum = crc.crc32(checksum, 445298)
  checksum = crc.crc32(checksum, { 1, 2, 3, 4, 5, 6 } )
  print(checksum)
      

crc.crc8 (function)
new_crc = crc.crc8 ( crc, data )
This function calculates the 8 bit crc checksum.
Parameters:
crc The current checksum.
data A number (one byte) or an array of bytes.
Return:
new_crc The new checksum.
Example:
  checksum = 0
  checksum = crc.crc8(checksum, 0x15)
  checksum = crc.crc8(checksum, 42)
  checksum = crc.crc8(checksum, { 1, 2, 3, 4, 5, 6 } )
  print(checksum)
      

crc.polynom16 (property)
The crc 16 polynom.
Example:
  crc.polynom16 = 0x5612
  print(crc.polynom16)
      

crc.polynom32 (property)
The crc 32 polynom.
Example:
  crc.polynom32 = 0x56560012
  print(crc.polynom32)
      

crc.polynom8 (property)
The crc 8 polynom.
Example:
  crc.polynom8 = 0x56
  print(crc.polynom8)
      


Table: dia

Functions for drawing curves in diagrams.


curve:append_data (function)
curve:append_data ( data_point )
Appends a data point to the curve.
Parameters:
data_point Tha data point. Can be an array(table) with two values or can be two single values.
Example:
  dia.delete_all()
  d = dia.new("Diagram1")
  curve = d:new_curve("Curve1") -- creates curve on left y axis

  -- data point is a table
  curve:append_data( { 1, 5 } )
  
  -- data point as to single values
  curve:append_data( 1, 5 )
      

curve:clear_data (function)
curve:clear_data ( )
Clears the data of the curve.
Example:
  dia.delete_all()
  d = dia.new("Diagram1")
  curve = d:new_curve("Curve1") -- creates curve on left y axis
  curve:set_data( {1, 2, 3}, {5, 7, 9} )
  curve:clear_data()
      

diagram:delete (function)
diagram:delete ( )
Deletes the diagram.
Example:
  dia.delete_all()
  d = dia.new("Diagram1")
  d:delete()
      

curve:delete (function)
curve:delete ( )
Removes the curve from the diagram.
Example:
  dia.delete_all()
  d = dia.new("Diagram1")
  curve1 = d:new_curve("Curve1") -- creates curve on left y axis
  curve2 = d:new_curve("Curve2", 1) -- creates curve on left y axis
  curve3 = d:new_curve("Curve3", 2) -- creates curve on right y axis
  curve2:delete()
  curve1:delete()
      

dia.delete_all (function)
dia.delete_all ( )
Deletes all diagrams.
Example:
  dia.delete_all()
  d = dia.new("Diagram1")
      

diagram:delete_all_curves (function)
diagram:delete_all_curves ( )
Delete all curves in the diagram.
Example:
  dia.delete_all()
  d = dia.new("Diagram1")
  curve1 = d:new_curve("Curve1") -- creates curve on left y axis
  curve2 = d:new_curve("Curve2", 1) -- creates curve on left y axis
  curve3 = d:new_curve("Curve3", 2) -- creates curve on right y axis
  d:delete_all_curves()
      

dia.new (function)
diagram_object = dia.new ( diagram_name )
Creates a new diagram.
Parameters:
diagram_name The name of the diagram.
Return:
diagram_object The new diagram object.
Example:
  d = dia.new("Diagram1")
      

diagram:new_curve (function)
curve_object = diagram:new_curve ( curve_name, y_axis )
Creates a new curve.
Parameters:
curve_name The name of the curve.
y_axis The y axis this curve shall be assigned to. (1 - left or 2 - right, default is 1) (This parameter is optional.)
Return:
curve_object The new curve object.
Example:
  dia.delete_all()
  d = dia.new("Diagram1")
  curve1 = d:new_curve("Curve1") -- creates curve on left y axis
  curve2 = d:new_curve("Curve2", 1) -- creates curve on left y axis
  curve3 = d:new_curve("Curve3", 2) -- creates curve on right y axis
      

diagram:save_csv (function)
diagram:save_csv ( file_name )
Saves the diagram as a CSV (comma seperated values, actually tabulator seperated values) file.
Parameters:
file_name The name of the CSV file.
Example:
  dia.delete_all()
  d = dia.new("Diagram1")
  curve = d:new_curve("Curve1") -- creates curve on left y axis
  curve:set_data( {1, 2, 3}, {5, 7, 9} )

  d:save_csv("diagram1.csv")
      

diagram:save_img (function)
diagram:save_img ( file_name )
Saves the diagram as a PNG (portable network graphic) image file.
Parameters:
file_name The name of the image file.
Example:
  dia.delete_all()
  d = dia.new("Diagram1")
  curve = d:new_curve("Curve1") -- creates curve on left y axis
  curve:set_data( {1, 2, 3}, {5, 7, 9} )

  d:save_img("diagram1.png")
      

curve:set_data (function)
curve:set_data ( data_point_list )
Sets all curve data points.
Parameters:
data_point_list The data points. Can be an array(table) of pairs or two arrays/tables with single values.
Example:
  dia.delete_all()
  d = dia.new("Diagram1")
  curve = d:new_curve("Curve1") -- creates curve on left y axis

  -- data points as array/table of pairs
  curve:set_data( { {1,5}, {2,7}, {3,9} } )
  
  -- data points as two arrays with single values
  curve:set_data( {1, 2, 3}, {5, 7, 9} )
      


Table: gfx

Functions for 2D pixel based drawings.


gfx.begin_update (function)
gfx.begin_update ( )
Disable graphics scene update to speed up the drawing operations.
Example:
  gfx.set_size(800, 600)
  gfx.clear()

  gfx.begin_update()
  for x=1, 500 do
    for y=1,500 do
      gfx.draw_pnt(x, y)
    end
  end
  gfx.end_update()
      

gfx.clear (function)
gfx.clear ( )
Clears the drawing.
Example:
  gfx.set_size(800, 600)
  gfx.clear()

  gfx.clear()
      

gfx.draw_circle (function)
gfx.draw_circle ( x, y, r )
Draws a circle with the current color.
Parameters:
x center x-coordinate
y center y-coordinate
r radius
Example:
  gfx.set_size(800, 600)
  gfx.clear()

  gfx.draw_circle(50, 50, 40)
      

gfx.draw_ellipse (function)
gfx.draw_ellipse ( x, y, rx, ry )
Draws an ellipse with the current color.
Parameters:
x center x-coordinate
y center y-coordinate
rx radius in x direction
ry radius in y direction
Example:
  gfx.set_size(800, 600)
  gfx.clear()

  gfx.draw_ellipse(50, 50, 40, 10)
      

gfx.draw_line (function)
gfx.draw_line ( x1, y1, x2, y2 )
Draws a straight line with the current color.
Parameters:
x1 x-coordinate start point
y1 y-coordinate start point
x2 x-coordinate end point
y2 y-coordinate end point
Example:
  gfx.set_size(800, 600)
  gfx.clear()

  gfx.draw_line(10, 10, 100, 100)
      

gfx.draw_pnt (function)
gfx.draw_pnt ( x, y )
Draws a point with the current color.
Parameters:
x x-coordinate
y y-coordinate
Example:
  gfx.set_size(800, 600)
  gfx.clear()

  gfx.draw_pnt(10, 10)
      

gfx.draw_polygon (function)
gfx.draw_polygon ( point_list )
Draws a polygon with the current color. The last point is connected with the first point.
Parameters:
point_list The polygon points as an array/table of pairs.
Example:
  gfx.set_size(800, 600)
  gfx.clear()

  gfx.draw_polygon( { {10,10}, {50,50}, {200,100} } )
      

gfx.draw_rect (function)
gfx.draw_rect ( x1, y1, x2, y2 )
Draws a rectangle with the current color.
Parameters:
x1 x-coordinate left upper corner
y1 y-coordinate left upper corner
x2 x-coordinate right bottom corner
y2 y-coordinate right bottom corner
Example:
  gfx.set_size(800, 600)
  gfx.clear()

  gfx.draw_rect(10, 10, 100, 100)
      

gfx.draw_text (function)
gfx.draw_text ( x, y, text )
Draws text.
Parameters:
x x-coordinate
y y-coordinate
text text
Example:
  gfx.set_size(800, 600)
  gfx.clear()

  gfx.draw_text(10, 10, "TEST")
      

gfx.end_update (function)
gfx.end_update ( )
Enable graphics scene update. (see also begin_update)
Example:
  gfx.set_size(800, 600)
  gfx.clear()

  gfx.begin_update()
  for x=1, 500 do
    for y=1,500 do
      gfx.draw_pnt(x, y)
    end
  end
  gfx.end_update()
      

gfx.fill_circle (function)
gfx.fill_circle ( x, y, r )
Draws a filled circle with the current fill color.
Parameters:
x center x-coordinate
y center y-coordinate
r radius
Example:
  gfx.set_size(800, 600)
  gfx.clear()

  gfx.fill_circle(50, 50, 40)
      

gfx.fill_ellipse (function)
gfx.fill_ellipse ( x, y, rx, ry )
Draws an filled ellipse with the current fill color.
Parameters:
x center x-coordinate
y center y-coordinate
rx radius in x direction
ry radius in y direction
Example:
  gfx.set_size(800, 600)
  gfx.clear()

  gfx.fill_ellipse(50, 50, 40, 10)
      

gfx.fill_polygon (function)
gfx.fill_polygon ( point_list )
Draws a filled polygon with the current fill color. The last point is connected with the first point.
Parameters:
point_list The polygon points as an array/table of pairs.
Example:
  gfx.set_size(800, 600)
  gfx.clear()

  gfx.fill_polygon( { {10,10}, {50,50}, {200,100} } )
      

gfx.fill_rect (function)
gfx.fill_rect ( x1, y1, x2, y2 )
Draws a filled rectangle with the current fill color.
Parameters:
x1 x-coordinate left upper corner
y1 y-coordinate left upper corner
x2 x-coordinate right bottom corner
y2 y-coordinate right bottom corner
Example:
  gfx.set_size(800, 600)
  gfx.clear()

  gfx.fill_rect(10, 10, 100, 100)
      

gfx.save_img (function)
gfx.save_img ( file_name )
Saves the current drawing as a PNG (portable network graphics) image file.
Parameters:
file_name The name of the image file.
Example:
  gfx.set_size(800, 600)
  gfx.clear()

  gfx.begin_update()
  for x=1, 500 do
    for y=1,500 do
      gfx.draw_pnt(x, y)
    end
  end
  gfx.end_update()

  gfx.save_img("image.png")
      

gfx.set_color (function)
gfx.set_color ( color )
Changes the current color.
Parameters:
color The color as a color name or as red (0..255), green (0..255) and blue (0..255) value.
Example:
  gfx.set_size(800, 600)
  gfx.clear()

  -- set color by name
  gfx.set_color("red")
  gfx.draw_line(10, 10, 100, 100)

  -- set color by values: red, green, blue
  gfx.set_color(100, 10, 250)
  gfx.draw_line(100, 10, 10, 100)
      

gfx.set_fill_color (function)
gfx.set_fill_color ( color )
Changes the current fill color.
Parameters:
color The color as a color name or as red (0..255), green (0..255) and blue (0..255) value.
Example:
  gfx.set_size(800, 600)
  gfx.clear()

  -- set color by name
  gfx.set_fill_color("red")
  gfx.draw_line(10, 10, 100, 100)

  -- set color by values: red, green, blue
  gfx.set_fill_color(100, 10, 250)
  gfx.draw_line(100, 10, 10, 100)
      

gfx.set_size (function)
gfx.set_size ( width, height )
Sets the size of the drawing area.
Parameters:
width The width of the drawing area.
height The height of the drawing area.
Example:
  gfx.set_size(800, 600)
  gfx.clear()

  gfx.begin_update()
  for x=1, 500 do
    for y=1,500 do
      gfx.draw_pnt(x, y)
    end
  end
  gfx.end_update()
      


Table: math_ex

Additional mathematical functions.


math_ex.calc_fft (function)
amplitude, frequency = math_ex.calc_fft ( count, frequency, data )
Calculates the fast fourier transformation of an array with values.
Parameters:
count The number of values must be a power of 2 in the range 2^2=4 to 2^17=131072.
frequency The signal sample frequency.
data The input values.
Return:
amplitude The amplitude vector.
frequency The frequency vector.
Example:
  -- create an input vector
  v = { 1, 2, 3, 2, 1, 0, 1, 2 }
  
  -- calculate the FFT
  a, f = fft.calc(8, 10e3, v)
  
  -- print the result
  array.print(a)
  array.print(f)
      

math_ex.lin_reg (function)
a, b, corr = math_ex.lin_reg ( x_array, y_array )
Calculates a linear regression line for an array with points using the least square method.
Parameters:
x_array X coordinates. (array of numbers.)
y_array y coordinates. (array of numbers.)
Return:
a The variable a of the equation f(x) = a + b * x
b The variable b of the equation f(x) = a + b * x
corr The correlation factor (0 .. 1)
Example:
  print(math_ex.reg_line( {0, 0}, {1, 4} ))
      

math_ex.mean (function)
res = math_ex.mean ( array )
Calculates the mean value from a list of values.
Parameters:
array Array of numbers.
Return:
res The mean value.
Example:
  print(math_ex.mean( {1, 1, 1, 5, 6, 3, 1, 1}, 3 ))
      

math_ex.mean_filter (function)
res = math_ex.mean_filter ( array, depth )
Applies the mean filter to the given values. The mean filter replaces the values by the arithmetic mean of the surrounding values.
Parameters:
array Array of numbers.
depth Mean filter depth.
Return:
res The filtered values.
Example:
  array.print(math_ex.mean_filter( {1, 1, 1, 5, 6, 3, 1, 1}, 3 ))
      

math_ex.median_filter (function)
res = math_ex.median_filter ( array, depth )
Applies the median filter to the given values. The median filter is a nonlinear digital filtering technique, used to remove noise.
Parameters:
array Array of numbers.
depth Median filter depth.
Return:
res The filtered values.
Example:
  array.print(math_ex.median_filter( {1, 1, 1, 5, 6, 3, 1, 1}, 3 ))
      


Table: string_ex

Functions for string manipulation.


string_ex.split (function)
string_array = string_ex.split ( string, delim )
Splits a string. The result is an array of strings.
Parameters:
string The string to be split.
delim The delimiter string.
Return:
string_array Array of strings.
Example:
  str_arr = string_ex.split("A,B,C", ",")
  print(str_arr[1])
      


Table: sys

Functions for system time and other.


sys.delay (function)
sys.delay ( time )
Stops the program execution for the given time. The time is counted from the begin of this function call.
Parameters:
time The time in seconds. The minimum wait time is 125 micro seconds.
Example:
  -- stop the program execution for 1ms from this point in time
  sys.delay(1e-3)
      

sys.time (property)
Returns the current system time in seconds since 1970-01-01.
Example:
  print(sys.time)
      

sys.time_str (property)
Returns the current system time as a formatted string in the form 21:49:25 2010-06-08.
Example:
  print(sys.time_str)
      


Table: tab

Functions to view data in a table.


tab.clear (function)
tab.clear ( )
Clears all data.
Example:
  tab.clear()
      

tab.save_csv (function)
tab.save_csv ( file_name )
Save the values in the table as a CSV (comma seperated values, actually tabulator seperated values) file.
Parameters:
file_name The name of the file.
Example:
  -- create a table with 10 rows and 5 columns
  tab.set_size(10, 5)
  for x = 1, 10 do
    for y = 1, 5 do
      tab.set_value(x, y, x * y)
    end
  end

  tab.save_csv("table.csv")
      

tab.set_column_values (function)
tab.set_column_values ( column, value )
Writes values in a table column.
Parameters:
column Column index (starts with 1).
value An array of values to be written in the table column.
Example:
  -- create a table with 10 rows and 5 columns
  tab.set_size(10, 5)
  tab.set_column_values(3, { "Test1", "Test2", "Test3" } )
      

tab.set_row_values (function)
tab.set_row_values ( row, value )
Writes values in a table row.
Parameters:
row Row index (starts with 1).
value An array of values to be written in the table row.
Example:
  -- create a table with 10 rows and 5 columns
  tab.set_size(10, 5)
  tab.set_row_values(3, { "Test1", "Test2", "Test3" } )
      

tab.set_size (function)
tab.set_size ( rows, columns )
Changes the number of rows and columns.
Parameters:
rows The new number of rows.
columns The new number of columns.
Example:
  -- create a table with 10 rows and 5 columns
  tab.set_size(10, 5)
      

tab.set_value (function)
tab.set_value ( row, column, value )
Writes a value in the table.
Parameters:
row Row index (starts with 1).
column Column index (starts with 1).
value The value to be written in the table.
Example:
  -- create a table with 10 rows and 5 columns
  tab.set_size(10, 5)
  tab.set_value(3, 2, "Test1")
  
  sys.delay(3)
  tab.clear()
  
  tab.set_value(5, 2, "Test2")
      


Table: vgfx

Functions for 2D vector drawings.


vgfx.clear (function)
vgfx.clear ( )
Clears the drawing.
Example:
  vgfx.clear()
      

vgfx.draw_circle (function)
vgfx.draw_circle ( x, y, r )
Draws a circle with the current color.
Parameters:
x center x-coordinate
y center y-coordinate
r radius
Example:
  vgfx.draw_circle(50, 50, 40)
      

vgfx.draw_ellipse (function)
vgfx.draw_ellipse ( x, y, rx, ry )
Draws an ellipse with the current color.
Parameters:
x center x-coordinate
y center y-coordinate
rx radius in x direction
ry radius in y direction
Example:
  vgfx.draw_ellipse(50, 50, 40, 10)
      

vgfx.draw_line (function)
vgfx.draw_line ( x1, y1, x2, y2 )
Draws a straight line with the current color.
Parameters:
x1 x-coordinate start point
y1 y-coordinate start point
x2 x-coordinate end point
y2 y-coordinate end point
Example:
  vgfx.draw_line(10, 10, 100, 100)
      

vgfx.draw_polygon (function)
vgfx.draw_polygon ( point_list )
Draws a polygon with the current color. The last point is connected with the first point.
Parameters:
point_list The polygon points as an array/table of pairs.
Example:
  vgfx.draw_polygon( { {10,10}, {50,50}, {200,100} } )
      

vgfx.draw_rect (function)
vgfx.draw_rect ( x1, y1, x2, y2 )
Draws a rectangle with the current color.
Parameters:
x1 x-coordinate left upper corner
y1 y-coordinate left upper corner
x2 x-coordinate right bottom corner
y2 y-coordinate right bottom corner
Example:
  vgfx.draw_rect(10, 10, 100, 100)
      

vgfx.draw_text (function)
vgfx.draw_text ( x, y, text )
Draws text.
Parameters:
x x-coordinate
y y-coordinate
text text
Example:
  vgfx.draw_text(10, 10, "TEST")
      

vgfx.fill_circle (function)
vgfx.fill_circle ( x, y, r )
Draws a filled circle with the current fill color.
Parameters:
x center x-coordinate
y center y-coordinate
r radius
Example:
  vgfx.fill_circle(50, 50, 40)
      

vgfx.fill_ellipse (function)
vgfx.fill_ellipse ( x, y, rx, ry )
Draws an filled ellipse with the current fill color.
Parameters:
x center x-coordinate
y center y-coordinate
rx radius in x direction
ry radius in y direction
Example:
  vgfx.fill_ellipse(50, 50, 40, 10)
      

vgfx.fill_polygon (function)
vgfx.fill_polygon ( point_list )
Draws a filled polygon with the current fill color. The last point is connected with the first point.
Parameters:
point_list The polygon points as an array/table of pairs.
Example:
  vgfx.fill_polygon( { {10,10}, {50,50}, {200,100} } )
      

vgfx.fill_rect (function)
vgfx.fill_rect ( x1, y1, x2, y2 )
Draws a filled rectangle with the current fill color.
Parameters:
x1 x-coordinate left upper corner
y1 y-coordinate left upper corner
x2 x-coordinate right bottom corner
y2 y-coordinate right bottom corner
Example:
  vgfx.fill_rect(10, 10, 100, 100)
      

vgfx.save_img (function)
vgfx.save_img ( file_name, width, height )
Saves the current drawing as a PNG (portable network graphics) image file.
Parameters:
file_name The name of the image file.
width The image width. (default: 1280) (This parameter is optional.)
height The image height. (default: 1024) (This parameter is optional.)
Example:
  -- set color by name
  vgfx.set_fill_color("red")

  -- set color by values: red, green, blue
  vgfx.set_fill_color(100, 10, 250)

  vgfx.save_img("small.png", 800, 600)
  vgfx.save_img("default.png")
      

vgfx.save_svg (function)
vgfx.save_svg ( file_name )
Saves the current drawing as a SVG (scalable vector graphic) file.
Parameters:
file_name The name of the file.
Example:
  -- set color by name
  vgfx.set_fill_color("red")

  -- set color by values: red, green, blue
  vgfx.set_fill_color(100, 10, 250)

  vgfx.save_svg("vgfx.svg")
      

vgfx.set_color (function)
vgfx.set_color ( color )
Changes the current color.
Parameters:
color The color as a color name or as red (0..255), green (0..255) and blue (0..255) value.
Example:
  -- set color by name
  vgfx.set_color("red")

  -- set color by values: red, green, blue
  vgfx.set_color(100, 10, 250)
      

vgfx.set_fill_color (function)
vgfx.set_fill_color ( color )
Changes the current fill color.
Parameters:
color The color as a color name or as red (0..255), green (0..255) and blue (0..255) value.
Example:
  -- set color by name
  vgfx.set_fill_color("red")

  -- set color by values: red, green, blue
  vgfx.set_fill_color(100, 10, 250)