-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
5,053 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +0,0 @@ | ||
ANSI I/O extensiond documentation | ||
|
||
Overview | ||
~~~~~~~~ | ||
|
||
The AIO (ANSI I/O) extension implements an I/O interface for Jim using only | ||
ANSI-C capabilities. The goal of the extension is to make Jim able to | ||
work with files in environments where the only assumption that can be | ||
done is that there is an ANSI-C compiler, or where the binary size matters | ||
(the AIO extension is very small compared to size that the real Tcl-alike | ||
channels implementation will have). | ||
|
||
Goals | ||
~~~~~ | ||
|
||
The AIO extension was developed in order to be able to experiment with | ||
two ideas. | ||
|
||
The first is the idea to build a replacement for autoconf/automake | ||
using the fact that Jim is small and ANSI-C, so the build process may | ||
build Jim with the assumption of an ANSI-C compiler, and a Jim script will | ||
check what exists in the system and will generate the Makefile and config.h. | ||
Autconf/make is such a crap that it's worth to experiment with this idea... | ||
|
||
The second idea is to create a micro starkit runtime, using a very small | ||
implementation of zlib called muzcat, and AIO. | ||
|
||
Usage | ||
~~~~~ | ||
|
||
The AIO extension exports an Object Based interface for files. In order | ||
to open a file use: | ||
|
||
set f [aio.open filename] | ||
|
||
this will open the file in read-only. It's possible to specify the mode: | ||
|
||
set f [aio.open filename w+] | ||
|
||
The [aio.open] command returns a file handle, that is a command name that | ||
can be used to perform operations on the file. A real example: | ||
|
||
Welcome to Jim version 0, Copyright (c) 2005 Salvatore Sanfilippo | ||
0 jim> package require aio | ||
1.0 | ||
0 jim> set f [aio.open /etc/passwd] | ||
aio.handle0 | ||
0 jim> $f gets line | ||
30 | ||
0 jim> puts $line | ||
root:x:0:0:root:/root:/bin/zsh | ||
|
||
The "methods" of an AIO file object are an exact copy of the usual | ||
Tcl commands for file I/O. In order to have the full list of | ||
the methods currenty supported, pass a bad method as argument, | ||
like in the example (but don't trust the example, the extension is | ||
in active development so probably there will be more functionality when | ||
you are reading this document): | ||
|
||
0 jim> $f helpme | ||
Runtime error, file "?", line 1: | ||
bad AIO method "helpme": must be close, seek, tell, gets, puts, or flush | ||
|
||
In order to close the file, use the 'close' method that will have as side effect | ||
to close the file and that the command associated with the file will be removed. | ||
|
||
Standard files | ||
~~~~~~~~~~~~~~ | ||
|
||
The AIO library is able to return handles about the standard C channels | ||
stdin, stdout and stderr. In order to do so just use: | ||
|
||
set f [aio.open standard input] | ||
|
||
Valid standard file names are "input", "output", "error". | ||
|
||
For standard files, the close method will just remove the command associated | ||
with the handle, without to really close the file. | ||
|
||
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +0,0 @@ | ||
Embedder HOWTO | ||
-------------- | ||
|
||
This document explains how to embed Jim into an existing application, in | ||
order to make the application scriptable, to write parts of the application | ||
in Jim on top of a C core, or just to use Jim as a configuration file format. | ||
|
||
STEP 1 | ||
------ | ||
|
||
Copy jim.c and jim.h into your project, and modify the Makefile in | ||
order to compile jim.c and link jim.o into your application. | ||
|
||
STEP 2 | ||
------ | ||
|
||
Include the file "jim.h" in your application, in the file where you | ||
defined your main() function. Before to include jim.h, only for this | ||
file you have to define JIM_EMBEDDED. So the two lines to add are: | ||
|
||
#define JIM_EMBEDDED | ||
#include "jim.h" | ||
|
||
Then add the call to Jim_InitEmbedded(); into your main() function. | ||
This call need to be placed before any other call to the Jim API. | ||
Example: | ||
|
||
int main(int argc, char **argv) { | ||
.... | ||
Jim_InitEmbedded(); | ||
... | ||
|
||
/* Here is possible to call other Jim API functions */ | ||
} | ||
|
||
NOTE: If you require to call the Jim API from other files of your project | ||
you have just to include "jim.h" WITHOUT to define JIM_EMBEDDED. | ||
This definition is only useful inside the file that calls Jim_InitEmbedded(), | ||
i.e. in the file containing your main() function. | ||
|
||
STEP 3 | ||
------ | ||
|
||
Use the Jim API in order to glue your program with Jim. First of all you | ||
probably want to create an interpreter, add some command, and use | ||
Jim_Eval() to execute Jim scripts from your application: | ||
|
||
#define JIM_EMBEDDED | ||
#include "jim.h" | ||
|
||
#include <stdio.h> | ||
|
||
static int foobarJimHelloCommand(Jim_Interp *interp, int argc, | ||
Jim_Obj *const *argv) | ||
{ | ||
printf("Hello World!\n"); | ||
return JIM_OK; | ||
} | ||
|
||
int main(void) | ||
{ | ||
Jim_Interp *interp; | ||
|
||
Jim_InitEmbedded(); | ||
printf("Welcome to The FooBar Application\n"); | ||
|
||
/* Create an interpreter */ | ||
interp = Jim_CreateInterp(); | ||
/* Add all the Jim core commands */ | ||
Jim_RegisterCoreCommands(interp); | ||
/* Add a new foobar.hello command to Jim */ | ||
Jim_CreateCommand(interp, "foobar.hello", foobarJimHelloCommand, NULL); | ||
/* Eval some Jim code. */ | ||
Jim_Eval(interp, "for {set i 0} {$i < 10} {incr i} {foobar.hello}"); | ||
return 0; | ||
} | ||
|
||
STEP 4 | ||
------ | ||
|
||
To test this example complile with: | ||
|
||
gcc main.c jim.c -ldl | ||
|
||
(you need to link against the 'dl' lib because Jim supports dynamic loading | ||
of extensions) | ||
|
||
The run the example with ./a.out. The output should be: | ||
|
||
Welcome to The FooBar Application | ||
Hello World! | ||
Hello World! | ||
Hello World! | ||
Hello World! | ||
Hello World! | ||
Hello World! | ||
Hello World! | ||
Hello World! | ||
Hello World! | ||
Hello World! | ||
|
||
Check the API reference for more information. | ||
|
||
|
||
Oops, something went wrong.