Initialization

Initialization — Overall setup of the Seed engine

Synopsis

#include <seed/seed.h>

struct              SeedEngine;
SeedEngine *        seed_init                           (gint *argc,
                                                         gchar ***argv);
SeedEngine *        seed_init_with_context_group        (gint *argc,
                                                         gchar ***argv,
                                                         SeedContextGroup group);
void                seed_engine_set_search_path         (SeedEngine *eng,
                                                         const gchar *path);
gchar **            seed_engine_get_search_path         (SeedEngine *eng);

Description

Before any other Seed functions can be used, you must initialize the engine, which creates an initial JavaScript context and sets up JavaScriptCore and GLib. To do this in most cases, you will use seed_init(), which will provide you with a SeedEngine. Only one SeedEngine is permitted per application; use a SeedContext to sandbox code execution.

Example 5. Very simple main function for a Seed program

int main (int argc, char **argv)
{
    SeedEngine * eng;
    SeedScript * script;
 
    /* Initialize the Seed engine */
    eng = seed_init(&argc, &argv);
 
    /* Create a simple SeedScript */
    script = seed_make_script(eng->context, "print('Hello, world!')", NULL, 0);
 
    /* Evaluate the SeedScript in the default context */
    seed_evaluate(eng->context, script, 0);
 
    g_free(script);
    return 0;
}


Details

struct SeedEngine

struct SeedEngine {
	JSGlobalContextRef context;
	JSObjectRef global;
	gchar **search_path;

	JSContextGroupRef group;
};


seed_init ()

SeedEngine *        seed_init                           (gint *argc,
                                                         gchar ***argv);

Initializes a new SeedEngine. This involves initializing GLib, creating an initial context with all of the default globals, and initializing various internal parts of Seed.

This function should only be called once within a single Seed application.

argc :

A reference to the number of arguments remaining to parse.

argv :

A reference to an array of string arguments remaining to parse.

Returns :

The newly created and initialized SeedEngine.

seed_init_with_context_group ()

SeedEngine *        seed_init_with_context_group        (gint *argc,
                                                         gchar ***argv,
                                                         SeedContextGroup group);

Initializes a new SeedEngine. This involves initializing GLib, creating an initial context (in group) with all of the default globals, and initializing various internal parts of Seed.

This function should only be called once within a single Seed application.

argc :

A reference to the number of arguments remaining to parse.

argv :

A reference to an array of string arguments remaining to parse.

group :

A SeedContextGroup within which to create the initial context.

Returns :

The newly created and initialized SeedEngine.

seed_engine_set_search_path ()

void                seed_engine_set_search_path         (SeedEngine *eng,
                                                         const gchar *path);

Sets the search path for the imports system.

eng :

A SeedEngine, on which to set the path.

path :

A const gchar*, a colon separated string containing the path to set

seed_engine_get_search_path ()

gchar **            seed_engine_get_search_path         (SeedEngine *eng);

Retrieves the search path for the imports system. The returned value is owned by the SeedEngine, and shouldn't be freed by the application writer.

eng :

A SeedEngine, to get the currently set search path.

Returns :

A null-terminated array of strings containing the paths.