Click here to Skip to main content
15,861,168 members
Articles / Containers / Virtual Machine
Article

Conscript IDE: An Integrated Development Environment (IDE) implementation for the Conscript scripting language

Rate me:
Please Sign up or sign in to vote.
4.90/5 (23 votes)
4 Sep 2008CPOL4 min read 99K   2.2K   158   26
The third and final article in the Conscript .NET scripting engine article series.

Simple script with accompanying byte code

Background

Embedded scripting engines have applications in several areas, including the ability to extend or modify the core functionality of a software application. In the game development world, scripting provides a means for the game engine developer to hand over control to the designer, allowing him or her to implement the game's plotline events, NPC behaviour, and so on, without the intervention of the game engine developer who may otherwise need to hard-wire game play logic into the game engine.

Introduction

The final article relating to the Conscript embeddable scripting engine for .NET presents an implementation of an IDE for Conscript, with functionality and look-and-feel reminiscent of Microsoft Visual Studio and other similar IDEs.

The IDE Windows application is included with this article in C# source form, and consists of the code for the scripting engine itself, the IDE, and additionally, an illustrative host function module to provide trigonometric functions and the ability to render 2D graphics. By default, the IDE application itself is a host function module that provides a Print function to allow for text output within the IDE's output window. Details for extending the scripting language with host functions is illustrated in the Dungeon of Despair scripted-game article presented as part of the Conscript article series. Techniques applied to integrate the Conscript scripting engine within the IDE application are illustrated in the previous articles, and hence will not be repeated here.

Using the Conscript IDE

The IDE window layout consists of a script source panel on the left-hand side, a virtual machine details panel on the right-hand side, and an output window at the bottom. In addition, a status bar beneath the output window provides compilation status and text cursor coordinates.

The script panel is a tabbed control that allows editing of multiple scripts. The IDE provides a ScriptLoader implementation that overrides the default script loading behaviour by giving priority to scripts loaded in the IDE. This allows one script within the IDE to include another script in the IDE even if it is not committed to disk.

The VM panel is also a tabbed control that provides access to compiled Conscript byte code, global, script, and local scopes, calling and parameter stacks, and thread locking states. The Byte Code tab within the VM panel allows setting of breakpoints, and also highlights the currently executing instruction during debugging.

Debugging a script using single-stepping

The Scope tabs allow viewing and editing of variables in the Global, Script, and Local scopes during debugging. The Stack tabs allow viewing of the current call stack and the parameter stack that regulates variable scoping within functions. Finally, the Locks tab displays the state of synchronisation locks used in multi-threaded scripts.

Debugging a script using single-stepping

The output panel provides compilation logs, and also acts as an output device for the Print() host function provided by default.

Registering a host function module within the IDE

The menu strip of the application is organised in a traditional layout, and consists of the menus File, Edit, Build, Debug, and Help. The File menu provides script source management and termination of the IDE. The Edit menu provides standard Undo/Redo and Cut/Copy/Paste functionality. The Build menu allows incremental or full re-building of scripts. Incremental building essentially only compiles modified scripts, while re-building discards all compiled scripts and recompiles them from scratch. The Build menu also provides access to a Build Settings dialog to control debug code generation and code optmisiation, and to a Host Environment dialog to allow registration of host function module plug-ins. The Debug menu provides standard debugging functionality including single-stepping, monitored execution, the ability to step into, over, and out of functions, and toggling and clearing of breakpoints. Finally, the Help menu provides access to an informative dialog box.

Using the Graphics Host Function Module

The illustrative module plug-in included in the source code implements two host function modules: one for basic trigonometric functions, and the other for simple 2D graphics. The trig functions provided are:

C#
any   math_abs(any);
float math_acos(float);
float math_asin(float);
float math_atan(float);
float math_atan2(float, float);
float math_ceiling(float);
float math_cos(float);
float math_cosh(float);
float math_e();
float math_floor(float);
float math_log(float);
float math_log2(float, float);
float math_max(float);
float math_min(float);
float math_pi();
int   math_round(float);
float math_round2(float, int);
any   math_sign(any);
float math_sin(float);
float math_sinh(float);
float math_sqrt(float);
float math_tan(float);
float math_tanh(float);
float math_rand(float);

The functions provided by the graphics module are:

C#
bool Gfx_Initialise(int, int);
bool Gfx_Shutdown();
bool Gfx_Clear();
bool Gfx_SetColour(int, int, int);
bool Gfx_SetLineWidth(int, int, int);
bool Gfx_DrawLine(int, int, int, int);
bool Gfx_DrawRectangle(int, int, int, int);
bool Gfx_FillRectangle(int, int, int, int);
bool Gfx_DrawEllipse(int, int, int, int);
bool Gfx_FillEllipse(int, int, int, int);
bool Gfx_DrawString(int, int, string);

The following script, also included with the module plug-in, illustrates the use of the Graphics host functions:

C#
function main()
{
    Gfx_Initialise(640, 480);
    var intensity = 0;
    for (var index = 0; index < 400; index += 10)
    {
        Gfx_SetColour(255 - intensity, 0, intensity);
        intensity += 5;

        Gfx_DrawLine(0, index, 400 - index, 0);

        Gfx_SetColour(intensity, 255, 0);
        Gfx_FillEllipse(index, 200, index / 4, index / 4);

        Gfx_SetColour(0, 0, 0);
        Gfx_DrawEllipse(index, 200, index / 4, index / 4);
    }

    // pause
    for (var pause = 0; pause < 200000; pause++); 

    Gfx_Shutdown();
}

A demo script illustrating the use of the graphics host function module

Related articles

History

  • 14/Mar/2008 - First version released.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Malta Malta
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionGood :) Pin
agoren23-Nov-12 15:48
agoren23-Nov-12 15:48 
GeneralThis is darn good code Pin
Cleveland Mark Blakemore13-Oct-10 13:30
Cleveland Mark Blakemore13-Oct-10 13:30 
GeneralRe: This is darn good code Pin
Colin Vella13-Oct-10 22:37
Colin Vella13-Oct-10 22:37 
GeneralRe: This is darn good code Pin
Cleveland Mark Blakemore14-Oct-10 0:42
Cleveland Mark Blakemore14-Oct-10 0:42 
GeneralRe: This is darn good code Pin
Member 139774061-Jan-20 23:55
Member 139774061-Jan-20 23:55 
GeneralTRY THIS SCRIPT :) Pin
Polymorpher17-Sep-09 17:07
Polymorpher17-Sep-09 17:07 
GeneralRe: TRY THIS SCRIPT :) Pin
Colin Vella18-Sep-09 10:51
Colin Vella18-Sep-09 10:51 
GeneralRe: TRY THIS SCRIPT :) Pin
Polymorpher18-Sep-09 14:42
Polymorpher18-Sep-09 14:42 
GeneralRe: TRY THIS SCRIPT :) [modified] Pin
Polymorpher18-Sep-09 16:25
Polymorpher18-Sep-09 16:25 
GeneralRe: TRY THIS SCRIPT :) [modified] Pin
sunildarji9-Nov-09 8:29
sunildarji9-Nov-09 8:29 
GeneralRe: TRY THIS SCRIPT :) [modified] Pin
Member 139774061-Jan-20 23:56
Member 139774061-Jan-20 23:56 
Questionwhy gfx functions can not be found? Pin
Seraph_summer28-Apr-09 9:10
Seraph_summer28-Apr-09 9:10 
AnswerRe: why gfx functions can not be found? Pin
Colin Vella28-Apr-09 11:37
Colin Vella28-Apr-09 11:37 
GeneralThanx Pin
Bassam Alugili24-Apr-09 5:46
Bassam Alugili24-Apr-09 5:46 
GeneralGood work Pin
cnmeta29-Mar-09 19:43
cnmeta29-Mar-09 19:43 
NewsConscript Open Source Project Pin
Colin Vella22-Oct-08 4:29
Colin Vella22-Oct-08 4:29 
GeneralImpressive! Pin
vbCoder2115-Sep-08 15:01
vbCoder2115-Sep-08 15:01 
GeneralGood work! Pin
Juergen Posny5-Sep-08 19:39
Juergen Posny5-Sep-08 19:39 
GeneralRe: Good work! Pin
Colin Vella6-Sep-08 12:40
Colin Vella6-Sep-08 12:40 
Question2 Questions Pin
User 45189735-Sep-08 14:27
User 45189735-Sep-08 14:27 
AnswerRe: 2 Questions [modified] Pin
Colin Vella6-Sep-08 12:23
Colin Vella6-Sep-08 12:23 
AnswerAmazing Pin
rcollina5-Sep-08 0:09
rcollina5-Sep-08 0:09 
GeneralRe: Amazing Pin
Colin Vella6-Sep-08 12:18
Colin Vella6-Sep-08 12:18 
Generalcongratulations on your article being edited Pin
Huisheng Chen4-Sep-08 20:11
Huisheng Chen4-Sep-08 20:11 
GeneralRe: congratulations on your article being edited Pin
Colin Vella4-Sep-08 21:45
Colin Vella4-Sep-08 21:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.