brl_maxlua.md 1.6 KB


id: brl.maxlua title: BRL.MaxLua

sidebar_label: Introduction

The MaxLua module provides a way to use the Lua scripting language from within Blitzmax programs.

Lua is a simple but fast and powerful scripting language. For more information on programming in Lua, please visit the official Lua site at https://www.lua.org

Here is an example of the MaxLua module in action:

SuperStrict

' Our TDemo type...
Type TDemo
	Method SayHello:String( name:String )
		Return "Hello " + name + "! Peace be with you..."
	End Method
End Type

' Register a demo object with Lua.
' Lua code can now access the object using the identifier "Demo".
Local demo:TDemo = New TDemo
LuaRegisterObject( demo, "Demo" )

' Source code to our little Lua program...
Local source:String = """
function hello()
	print( Demo.SayHello( 'Fredborg' ) )
end
function goodbye()
	print( Demo.SayHello( 'CandyMan' ) )
end
"""

' Create a Lua 'class' and set it's source code...
Local class:TLuaClass = TLuaClass.Create( source )

' Now, create an instance of the class.
Local instance:TLuaObject = TLuaObject.Create( class, Null )

' We can no invoke methods of the class.
instance.Invoke( "hello", Null )
instance.Invoke( "goodbye", Null )

Types

Type Description
TLuaObject A Lua 'object'
TLuaClass A Lua 'class'

Functions

Function LuaRegisterObject( obj:Object,name:String )

Register a global object with Lua

Once registered, the object can be accessed from within Lua scripts using the name identifer.