Jump to content
  • entries
    941
  • comments
    5,894
  • views
    867,851

Debugging Lua Apps


Josh

2,698 views

 Share

Scripting support is very important in the new engine. The script implementation in the old engine was great for quickly adding animation and simple behavior to objects, but wasn't capable of supporting advanced gameplay. I've put a lot of work into our implementation of Lua script to bring it to a new level.

 

In the old engine, if a script error occurred the program would simply crash. The new engine supports detailed error handling and will automatically open files and show you where an error occurs in a script:

blogentry-1-0-65137400-1343449486_thumb.jpg

 

You can insert breakpoints in your program with the Debug:Stop() command. When a breakpoint is hit, the program pauses. You can browse all variables running in the virtual machine in the script debug pane. You can even see actual memory addresses of C++ objects in the Lua virtual machine!:

blogentry-1-0-07843900-1343449558_thumb.jpg

 

Of course, you can also step through your script line by line with code stepping:

blogentry-1-0-86995600-1343449582_thumb.jpg

 

You can modify object scripts, and when you hit F5 the current scene will be saved and loaded in your project. The editor launches the game as an external executable, you don't have to worry about messing up your editing session, and you can even debug the virtual machine in C++ programs. This makes the editor stable and solid, and game iteration is still very fast.

blogentry-1-0-93125200-1343450190_thumb.jpg

 

By focusing on improved Lua support and really digging into the details of the language, I hope we can provide a scripting environment that is very capable and pleasant to use.

  • Upvote 2
 Share

3 Comments


Recommended Comments

This is an amazing step in the right direction for sure! A question of common implementation for breakpoints however is not to actually have code that we type, but to do it behind the scenes for us in the form of clicking an area in the margins to set breakpoints. Is that not something you're interested in doing here? If not could you create some sort of global remove breakpoints menu option that will look for that line of code and remove them all, and/or all in the specific file.

Link to comment

That would be cool, but I don't know of any way to make a cross-platform text editor with syntax highlighting and line numbers. Scintilla is the only one I know of and it's undocumented and buggy. I'm using the actual OS text editor control on Windows and Mac right now, with my own syntax highlighting code. I can create a gutter next to the text, but it would have to sync with the text area scrolling, and I don't know if that's possible.

 

This works fine, but the scroll syncing is the problem:

' createtextarea.bmx

Import MaxGui.Drivers

Strict 

Const GUTTERWIDTH:Int=35

Global window:TGadget = CreateWindow( "My Window", 130, 20, 640, 480 )

Global textarea:TGadget = CreateTextArea( 0, 0, ClientWidth(window), ClientHeight(window), window )
SetMargins textarea,GUTTERWIDTH+2

'Gutter:
Local gutter2:TGadget=CreatePanel(0,0,GUTTERWIDTH+1, textarea.ClientHeight(),textarea)
SetGadgetLayout gutter2,1,0,1,1
SetGadgetColor gutter2,192,192,192
Local gutter:TGadget=CreatePanel(0,0,GUTTERWIDTH, gutter2.ClientHeight(),gutter2)
SetGadgetColor gutter,220,220,220
SetGadgetLayout gutter,1,1,1,1
Local label:TGadget
Local lineheight:Int=14
Local font:TGUIFont=LoadGuiFont("Arial",10)
For Local i:Int=1 To 1000
label=CreateLabel(i,0,(i-1)* lineheight,gutter.ClientWidth(), 12,gutter,LABEL_RIGHT)
label.SetLayout 1,0,1,0
SetGadgetSensitivity(label,SENSITIZE_MOUSE)
SetGadgetFont label,font
Next

SetGadgetLayout( textarea, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED )
SetGadgetText( textarea, "A TextArea gadget. :-)~n~nOne line...~n...and then another!")
ActivateGadget( textarea )
For Local n:Int=0 To 300
AddTextAreaText textarea,"Hello, how are you today?~n"
Next

' Select the entire third (index: 2 [base-0]) line.
SelectTextAreaText( textarea, 2, 1, TEXTAREA_LINES )


' Output the properties of the current text selection (should be 1, 1 as set above).
Print "TextAreaCursor(): " + TextAreaCursor( textarea, TEXTAREA_LINES )
Print "TextAreaSelLen(): " + TextAreaSelLen( textarea, TEXTAREA_LINES )

While WaitEvent()
Print CurrentEvent.ToString()
Select EventID()
	Case EVENT_MOUSEDOWN
		SetGadgetColor TGadget(EventSource()),0,0,255,1
		SetGadgetColor TGadget(EventSource()),255,255,255,0
	Case EVENT_WINDOWCLOSE
		End
	Case EVENT_APPTERMINATE
		End
End Select
Wend

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...