GALua
Geometric Algebra Library for the Lua Programming Language

Requiring the GALua module

To use the GALua module, begin by requiring it in your script. Like so...

-- Grab the GALua API table.
local galua_api = require "galua"

Of course, this will fail if the GALua.dll file has not been installed in a place where Lua can find it. It is up to you to make sure that it is installed correctly, or that you tell Lua where it can find the module. Place the GALua.dll with your other Lua modules, or adjust your LUA_CPATH environment variable to point to the location where you have placed GALua.dll.

Another problem that can occur is that of multiple virtual machines being detected by Lua. In this event, Lua bails out with this as an error. The problem is that the program hosting Lua, (the program with a Lua virtual machine embedded in it), is not sharing that virtual machine with the one being used by the Lua extension module, in this case GALua. GALua run-time links against Lua. If the host program does the same thing, then there's no problem, because the shared libraries loaded by a process are managed by the operating system, which can tell if a requested library is already loaded. If, on the other hand, the host program is compile-time linked against Lua, there's no way that GALua can share the host program's virtual machine. This is a problem on Windows, but one that is solvable on Unix. Anyhow, this problem has given me personally a great bit of difficulty, and better solutions to the problem are under investigation.

Once you have access to the API table, almost everything you'd ever want to do with the module can be accessed through this table. (Everything else is accessible as a meta-method of the multivector data-type. More on that later!) To see what's available, you might simply do a dump of the API table.

for key, value in pairs( galua_api ) do
  if type( value ) == "function" then
    print( key )
  end
end

As of this writing, this prints the following text to your console. Your results, of course, may be in a different order!

to_number
def_bar
version
to_latex_string
mag
copy
add
def_sig
reverse
from_string
op
dif
sum
left_inverse
right_inverse
inverse
ip
gp_inv
gp
set_grade_part
to_string
get_grade_part
coef
neg
sub
def_basis
from_number

Many of these functions perform mathematical operations, but a program that uses these exclusively would get too wordy and combersome to write. Such operations, therefore, have been provided as meta-methods that overload some of Lua's built-in binary and unary operators. More on this is given in a subsequent tutorial.

Among the functions printed above you'll find the version function. Taking no arguments, this function simply returns the version number of the GALua module you're using. At the time of this writing, it would return 1.0. After determining which version of the module you're using, you might have your script check to make sure that this is the version it was written for before moving on. I don't have any plans to maintain backwards compatibility, but I also don't expect the API to change much at all, so there's not really much to worry about here.

Well, this is just great! Now that you're up and running with the module, we can get started using it. On to the next tutorial!

Defining the geometric algebra

Copyright (C) 2013, by Spencer T. Parkin