Lua is the main programming language supported in and embedded inside SIMION 8. It supplants the SIMION 7 PRG code (as well as SL which compiled down to PRG), though PRG is still available in SIMION 8 for backward compatibility. Lua can also call C/C++ (see “extension” examples in SIMION 8.0). An example is below:

-- SIMION accel_adjust segment.  Called to override particle acceleration.
function segment.accel_adjust()
  if ion_time_step  == 0 then return end   -- skip if zero time step
  if linear_damping == 0 then return end   -- slip if damping set to zero

  -- Compute correction factor.
  linear_damping = abs(linear_damping)          -- force damping factor positive
  local tterm = ion_time_step * linear_damping  -- time constant
  local factor = (1 - exp(-tterm)) / tterm      -- correction factor

  -- Compute new x, y, and z accelerations.
  ion_ax_mm = factor * (ion_ax_mm - ion_vx_mm * linear_damping)
  ion_ay_mm = factor * (ion_ay_mm - ion_vy_mm * linear_damping)
  ion_az_mm = factor * (ion_az_mm - ion_vz_mm * linear_damping)

Lua itself is a standard scripting programming language that has been brought into SIMION 8. Details are available at (see About Lua and the Lua Documentation). We recommend the book Programming in Lua (first edition is free online, second edition is in print). There is also a Lua Tutorial and Lua Reference Manual.

Lua suits SIMION well for its efficiency (speed comparable to PRG), it’s simplicity, it’s small size, it’s flexibility (much more capable than PRG), and it’s data definition capabilities (Lua is even used as the basis for the new FLY2 format). Lua programs (unlike SL ones) do not need to be compiled but rather can be run directly in SIMION. Lua can interface to other programs or programming languages via a simple os.execute call or LuaCOM, which is used in one of the SIMION examples to control Excel from SIMION. The SIMION batch-mode capabilities offers a Lua interface as well (based on the command-line interface).

If you wish to control Excel from Lua, see the Microsoft Excel Object Model. You can find this in the Microsoft Excel Help, in Contents, under the topic “Microsoft Excel Help Information Excel Visual Basic Reference Excel Object Model” (might be located elsewhere depending on your version of Excel). There is also an online version. The examples in the Microsoft Documentation are largely written in the VisualBasic lanuage, so some translation is required to similarly do this under Lua. See the SIMION Excel examples and the LuaCOM Reference for an idea of how to perform this translation.


This page is abridged from the full SIMION "Supplemental Documentation" (Help file). The following additional sections can be found in the full version of this page accessible via the "Help > Supplemental Documentation" menu in SIMION 8.1.1 or above:
  • Versions