pcb-rnd knowledge pool

 

Live scripting

live_script by Tibor 'Igor2' Palinkas on 2019-04-02

Tags: howto, live, script, scripting, awk, mawk, gui

node source

 

 

Abstract: Live scripting is an easy, graphical script editing setup for rapid script development. This article demonstrates how to use the new feature to develop awk scripts.

 

Demo

The following video demonstrates how to use the live scripting feature. First, open the live scripting dialog, either using the LiveScript action or the menu (plugins/script/open live scripting dialog...).

It is possible to keep multiple live scripting dialogs open: the second argument of the LiveScript() action is the unique name of the live script session, which is user assigned - the one started from the menu or without arguments is called "default".

The awk script used for the demo is available for download. Please make sure you install libmawk before compiling fungw if you want to run it.

How to install

First, you need install scripting . Please note: this does include reconfiguring, recompiling and reinstalling pcb-rnd from source, there is no way around this at the moment. Make sure you install your preferred script language interpreter libs' dev package or headers before compiling fungw.

Once fungw installation is done and pcb-rnd is recompiled, scripting is automatically available.

How to use live scripting

The purpose of live scripting is to ease development of short scripts. There are two modes of operation: persistent and non-persistent .

Non-persistent , which is the default mode, is similar to script one-liners: the script is interpreted and ran immediately and then unloaded and destroyed. This is useful for cases when scripting is used to generate objects or make queries or modifications to the board. In this mode the 'undo' button is used to undo all changes made by the script. Undo is available only if there is no further modifications done by the user after the script has finished. In any case, plain old undo works and should be able to undo anything the script has done. A re-run button is provided for fast test-modify-test iterations: it does a stop-undo-run combination.

The persistent mode is activated by clicking the 'persistent' checkbox on the bottom left of the dialog box. In this mode the script is loaded and run, and is kept running. The initialization part of the script shall not contain infinite loops (that would hang pcb-rnd), but the script may install async timers, register actions, menus, etc and they persist as long as the script is running (the 'run' button is disabled). The script can be stopped using the 'stop' button - this will unregister all timers, actions, menus, etc. The 'undo' button affects any board edit done by the script during initialization (later changes are not tracked). The re-run button does the same stop-undo-run combination as in non-persistent mode.

Before running a script, you must select the scripting language using the combo box on the bottom. pcb-rnd doesn't make any effort at any stage of live scripting to guess the language, not even when you load a script from a file.

How to script pcb-rnd

Live scripting is only one way of scripting pcb-rnd. Another way is stored user scripts, typically used for extending pcb-rnd with new features. A third way is entering simple one-liners at the command line.

More info on these and what pcb-rnd functions a script can call is in the pcb-rnd user manual for scripting.

FAQ

1. Why can't we have syntax highlighting or searc&replace?

Live scripting is not an IDE for your favorite scripting language. The goal is not to provide a full featured editor that is aware of the language you are using, but to provide a simple GUI to easy entering and editing multi-line scripts. If you are developing a large script, live scripting should be used to debug and refine small parts of the script, one by one, isolated from the rest.

In return the whole feature is surprisingly small, below 500 sloc . This is about as much as a GUI for scripting is worth in pcb-rnd, we don't plan to grow it to a 100k lines IDE.

2. Why can't I set breakpoints or step line by line or watch variables?

See above: pcb-rnd is not a scripting IDE.

3. There are no scripting languages listed in the combo box!

You failed to install fungw or recompile pcb-rnd after fungw installation or you didn't compile fungw with any scripting language libs available.

4. How to have multiple live script windows open?

Run action:


LiveScript(new, "scriptname")

Use unique script names. Once you close a live script dialog, the script in it is lost unless you have used the 'save' button to save it on disk.