Hello, World, Take One

Here is a very simple program which uses the CLR classes to write out the value of the square root of two:

require 'CLRPackage'
 
import "System"
 
Console = luanet.import_type "System.Console"
Math = luanet.import_type "System.Math"
 
Console.WriteLine("sqrt(2) is {0}",Math.Sqrt(2))

The first task for any LuaInterface program is to load any assemblies needed, and the second task is to import the types. In this case, the Console and Math classes are loaded explicitly, and we call their static methods WriteLine and Sqrt.LuaInterface will convert Lua numbers and strings into their .NET equivalents for us.

Like all hello programs, it is basically silly; the equivalent pure Lua program is of course just this one-liner:

print("sqrt(2) is "..math.sqrt(2))

But these techniques will be used to bring all the considerable power of the .NET framework into Lua programs, like the ability to easily write good-looking GUI applications, examine running processes, etc.