intro.bbdoc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. The MaxLua module provides a way to use the Lua scripting language from within Blitzmax programs.
  2. 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
  3. Here is an example of the MaxLua module in action:
  4. {{
  5. SuperStrict
  6. ' Our TDemo type...
  7. Type TDemo
  8. Method SayHello:String( name:String )
  9. Return "Hello " + name + "! Peace be with you..."
  10. End Method
  11. End Type
  12. ' Register a demo object with Lua.
  13. ' Lua code can now access the object using the identifier "Demo".
  14. Local demo:TDemo = New TDemo
  15. LuaRegisterObject( demo, "Demo" )
  16. ' Source code to our little Lua program...
  17. Local source:String = """
  18. function hello()
  19. print( Demo.SayHello( 'Fredborg' ) )
  20. end
  21. function goodbye()
  22. print( Demo.SayHello( 'CandyMan' ) )
  23. end
  24. """
  25. ' Create a Lua 'class' and set it's source code...
  26. Local class:TLuaClass = TLuaClass.Create( source )
  27. ' Now, create an instance of the class.
  28. Local instance:TLuaObject = TLuaObject.Create( class, Null )
  29. ' We can no invoke methods of the class.
  30. instance.Invoke( "hello", Null )
  31. instance.Invoke( "goodbye", Null )
  32. }}