![]() | ![]() | |||||||||||||||
|
Calling SparForte from C: A TutorialCertain kinds of programs, such as games or the Gimp, allow users to write their own scripts For example, there are game scripts that change the behavior of enemies, or Gimp scripts that apply imaging effects to a photograph. SparForte can be used as a scripting language for these kind of applications. There is a special pragma, pragma restriction( no_external_commands ), that will disable all operating system commands. If you are using SparForte strictly as a scripting language, this pragma will guarantee that your SparForte scripts will be portable to other operating systems. In addition, if you use pragma ada_95, your scripts will have less errors and commonly used scripts can compiled with GCC Ada (with only minor changes) for extra speed. Scripts that interact with other programs must be able to share data with the SparForte scripts. In order to share variables with SparForte, you will have to export your variables as environment variables or add the appropriate declarations to the scripts before you run them with SparForte. A simple C example called scripting.c is included in the examples directory.
/* -------------------------------------------- */
#include <stdio.h>
int main() {
/* assign a value to i */ i = 5; /* export i */ sprintf( i_string, "i_string=%d", i ); // convert i to a
string
/* Create the script to run */ f = fopen( "scripting_example.sp", "w" );
/* Run the script. If successful, delete script */
Example: Hello World
|
![]() Command Prompt Tutorial 1: SparForte as a Calculator Command Prompt Tutorial 2: Basic Shell Commands Command Prompt Tutorial 3: Working with Databases Script Tutorial 1: Basic Commands Scripts Script Tutorial 2: Intermediate Program Scripts Template Tutorial 1: Basic Templates Template Tutorial 2: Intermediate Templates GCC Tutorial: Compiling SparForte Scripts Debugging Tutorial - Using the SparForte Debugger |
![]() |
![]() |