LUA scripting for BMX

BlitzMax Forums/BlitzMax Programming/LUA scripting for BMX

Here's something that neat. A quick console example I've knocked up that allows you to type LUA commands in and have them executed when you pressed ENTER... :) :


Strict

Import Pub.scriptengine

' Call our entry point
main()

Function main()

	Local SEObject:ScriptEngine = New ScriptEngine
	Local command:String = ""
		
	Print ("Some commands to try (LUA commands are case sensitive):")
	Print ("a = 1 + 1")
	Print ("print (a)")
	Print ("b = a + 3")
	Print ("print (b)")

	Repeat
	
		Print ("Enter lua command! (quit to exit)")
		command = Input (":")
		
		If (Lower(command) = "quit") Then End
		
		' Load script from string
		If (SEObject.SetScriptText(command, "ConsoleCommand")) Then
		
			' Run the script
			If (Not SEObject.RunScript()) Then
				Print "Error: " + SEObject.GetLastErrorString()
			Else
				Print "Done."
			End If
		Else
			Print "Error: " + SEObject.GetLastErrorString()
		End If
	Forever

	' Shut it down
	SEObject.ShutDown()	
End Function