intro.bbdoc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 http://www.lua.org
  3. Here is an example of the MaxLua module in action:
  4. {{
  5. Strict
  6. 'Our TDemo type...
  7. '
  8. Type TDemo
  9. Method SayHello$( name$ )
  10. Return "Hello "+name+"! Peace be with you..."
  11. End Method
  12. End Type
  13. 'Register a demo object with Lua.
  14. '
  15. 'Lua code can now access the object using the identifier "Demo".
  16. '
  17. Local demo:TDemo=New TDemo
  18. LuaRegisterObject demo,"Demo"
  19. 'source code to our little Lua program...
  20. '
  21. Local source$=..
  22. "function hello()~n"+..
  23. "print( Demo.SayHello( 'Fredborg' ) )~n"+..
  24. "end~n"+..
  25. "function goodbye()~n"+..
  26. "print( Demo.SayHello( 'CandyMan' ) )~n"+..
  27. "end~n"
  28. 'create a Lua 'class' and set it's source code...
  29. '
  30. Local class:TLuaClass=TLuaClass.Create( source )
  31. 'Now, create an instance of the class.
  32. '
  33. Local instance:TLuaObject=TLuaObject.Create( class,Null )
  34. 'We can no invoke methods of the class.
  35. '
  36. instance.Invoke "hello",Null
  37. instance.Invoke "goodbye",Null
  38. }}