mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-25 13:30:49 +02:00
* Initial check-in
git-svn-id: trunk@14857 -
This commit is contained in:
parent
39224aad96
commit
34f551ad5e
10
.gitattributes
vendored
10
.gitattributes
vendored
@ -4111,6 +4111,16 @@ packages/librsvg/Makefile svneol=native#text/plain
|
|||||||
packages/librsvg/Makefile.fpc svneol=native#text/plain
|
packages/librsvg/Makefile.fpc svneol=native#text/plain
|
||||||
packages/librsvg/fpmake.pp svneol=native#text/plain
|
packages/librsvg/fpmake.pp svneol=native#text/plain
|
||||||
packages/librsvg/src/rsvg.pas svneol=native#text/plain
|
packages/librsvg/src/rsvg.pas svneol=native#text/plain
|
||||||
|
packages/libsee/Makefile svneol=native#text/plain
|
||||||
|
packages/libsee/Makefile.fpc svneol=native#text/plain
|
||||||
|
packages/libsee/README.txt svneol=native#text/plain
|
||||||
|
packages/libsee/examples/mod_stream.pp svneol=native#text/plain
|
||||||
|
packages/libsee/examples/teststream.pp svneol=native#text/plain
|
||||||
|
packages/libsee/examples/testwrite.pp svneol=native#text/plain
|
||||||
|
packages/libsee/examples/tlibsee.pp svneol=native#text/plain
|
||||||
|
packages/libsee/fpmake.pp svneol=native#text/plain
|
||||||
|
packages/libsee/src/libsee.pas svneol=native#text/plain
|
||||||
|
packages/libsee/src/libseewrap.c svneol=native#text/plain
|
||||||
packages/libxml/Makefile svneol=native#text/plain
|
packages/libxml/Makefile svneol=native#text/plain
|
||||||
packages/libxml/Makefile.fpc svneol=native#text/plain
|
packages/libxml/Makefile.fpc svneol=native#text/plain
|
||||||
packages/libxml/examples/Makefile svneol=native#text/plain
|
packages/libxml/examples/Makefile svneol=native#text/plain
|
||||||
|
2802
packages/libsee/Makefile
Normal file
2802
packages/libsee/Makefile
Normal file
File diff suppressed because it is too large
Load Diff
30
packages/libsee/Makefile.fpc
Normal file
30
packages/libsee/Makefile.fpc
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#
|
||||||
|
# Makefile.fpc for InterBase bindings
|
||||||
|
#
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name=libsee
|
||||||
|
version=2.5.1
|
||||||
|
|
||||||
|
[target]
|
||||||
|
units=libsee
|
||||||
|
exampledirs=examples
|
||||||
|
|
||||||
|
[require]
|
||||||
|
libc=y
|
||||||
|
|
||||||
|
[install]
|
||||||
|
fpcpackage=y
|
||||||
|
|
||||||
|
[default]
|
||||||
|
fpcdir=../..
|
||||||
|
|
||||||
|
[compiler]
|
||||||
|
includedir=src
|
||||||
|
sourcedir=src
|
||||||
|
|
||||||
|
[shared]
|
||||||
|
build=n
|
||||||
|
|
||||||
|
[rules]
|
||||||
|
.NOTPARALLEL:
|
27
packages/libsee/README.txt
Normal file
27
packages/libsee/README.txt
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
This package contains an interface unit to the libSEE library.
|
||||||
|
|
||||||
|
SEE = Simple ECMAScript Engine
|
||||||
|
|
||||||
|
libSEE is a library that executes Javascript code, and is written by David Leonard.
|
||||||
|
|
||||||
|
The library itself must be obtained separately from
|
||||||
|
http://www.adaptive-enterprises.com.au/~d/software/see/
|
||||||
|
The library tarball contains installation instructions.
|
||||||
|
Make sure you compile it with Garbage collection.
|
||||||
|
|
||||||
|
the libsee unit was generated from the header files of version 3.1 of
|
||||||
|
libsee. Note that all type names have been prepended with T. That means
|
||||||
|
that the C struct
|
||||||
|
SEE_interpreter
|
||||||
|
becomes
|
||||||
|
TSEE_interpreter
|
||||||
|
in pascal.
|
||||||
|
|
||||||
|
The examples directory contains some examples of what can be done
|
||||||
|
with libsee, including how to integrate Object Pascal objects in the
|
||||||
|
Javascript runtime environment.
|
||||||
|
|
||||||
|
Enjoy,
|
||||||
|
|
||||||
|
Michael.
|
478
packages/libsee/examples/mod_stream.pp
Normal file
478
packages/libsee/examples/mod_stream.pp
Normal file
@ -0,0 +1,478 @@
|
|||||||
|
unit mod_stream;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, libsee;
|
||||||
|
|
||||||
|
Procedure RegisterStreamModule;
|
||||||
|
Procedure RegisterWriteModule;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
{ ---------------------------------------------------------------------
|
||||||
|
General auxiliary functions
|
||||||
|
---------------------------------------------------------------------}
|
||||||
|
|
||||||
|
Function ValueToString(V : TSee_Value) : string;
|
||||||
|
|
||||||
|
Var
|
||||||
|
PS : Ptcuint;
|
||||||
|
PD : PChar;
|
||||||
|
I : Integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
SetLength(Result,v.u._string^.length);
|
||||||
|
If Length(Result)<>0 then
|
||||||
|
begin
|
||||||
|
PD:=PChar(Result);
|
||||||
|
PS:=v.u._string^.data;
|
||||||
|
For I:=0 to length(Result)-1 do
|
||||||
|
begin
|
||||||
|
PD^:=Char(PS^ and $ff);
|
||||||
|
Inc(PD);
|
||||||
|
Inc(PS);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure CreateJSObject(Interp : PSEE_Interpreter; Parent : PSEE_Object;AName : PSEE_String; Obj : PSee_Object);
|
||||||
|
|
||||||
|
var
|
||||||
|
V : PSEE_Value;
|
||||||
|
|
||||||
|
begin
|
||||||
|
v:=new_see_value;
|
||||||
|
see_set_object(V,Obj);
|
||||||
|
see_object_put(interp,parent,AName,V,SEE_ATTR_DEFAULT);
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure CreateJSNumber(Interp : PSEE_Interpreter; Obj : PSee_Object; AName : PSEE_String; AValue : TSEE_number_t);
|
||||||
|
|
||||||
|
var
|
||||||
|
V : PSEE_Value;
|
||||||
|
|
||||||
|
begin
|
||||||
|
v:=new_SEE_value;
|
||||||
|
see_set_number(V,AValue);
|
||||||
|
see_object_put(Interp,Obj,AName,v,SEE_ATTR_DEFAULT);
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure CreateJSFunction(Interp : PSEE_Interpreter; Obj : PSee_Object; Func : TSEE_call_fn_t; AName : PSEE_String; Len : Integer);
|
||||||
|
|
||||||
|
var
|
||||||
|
V : PSEE_Value;
|
||||||
|
|
||||||
|
begin
|
||||||
|
v:=new_SEE_value;
|
||||||
|
see_set_object(V,see_cfunction_make(interp,Func,AName,len));
|
||||||
|
see_object_put(Interp,Obj,AName,v,SEE_ATTR_DEFAULT);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ ---------------------------------------------------------------------
|
||||||
|
Stream module support
|
||||||
|
---------------------------------------------------------------------}
|
||||||
|
Var
|
||||||
|
StreamModule : TSEE_module;
|
||||||
|
StreamObjectDef,
|
||||||
|
StreamPrototypeDef : PSEE_objectclass;
|
||||||
|
|
||||||
|
WriteModule : TSEE_module;
|
||||||
|
|
||||||
|
Type
|
||||||
|
TStreamModuleData = record
|
||||||
|
Stream : PSEE_object;
|
||||||
|
Prototype : PSEE_object;
|
||||||
|
Error : PSEE_object;
|
||||||
|
end;
|
||||||
|
PStreamModuleData = ^TStreamModuleData;
|
||||||
|
|
||||||
|
TStreamObject = record
|
||||||
|
native : TSEE_native;
|
||||||
|
Stream : TStream;
|
||||||
|
end;
|
||||||
|
PSTreamObject = ^TStreamObject;
|
||||||
|
|
||||||
|
Var
|
||||||
|
GStreamRead,
|
||||||
|
GStreamWrite,
|
||||||
|
GStreamSeek,
|
||||||
|
GStreamSize,
|
||||||
|
GStreamPosition,
|
||||||
|
GStreamFree,
|
||||||
|
GStreamfmCreate,
|
||||||
|
GStreamfmOpenRead,
|
||||||
|
GStreamfmOpenWrite,
|
||||||
|
GStreamfmOpenReadWrite,
|
||||||
|
GStreamStream,
|
||||||
|
GStreamError,
|
||||||
|
GStreamPrototype : PSEE_String;
|
||||||
|
|
||||||
|
Procedure StreamAlloc(Interp : PSEE_Interpreter); cdecl;
|
||||||
|
|
||||||
|
begin
|
||||||
|
PPointer(see_module_private(Interp,@StreamModule))^:=new(PStreamModuleData);
|
||||||
|
end;
|
||||||
|
|
||||||
|
Function PrivateData(Interp : PSEE_Interpreter) : PStreamModuleData;
|
||||||
|
begin
|
||||||
|
Result:=PStreamModuleData((see_module_private(Interp,@StreamModule))^)
|
||||||
|
end;
|
||||||
|
|
||||||
|
Function AsFile(i:PTSEE_interpreter; obj:PTSEE_object) : PStreamObject;
|
||||||
|
|
||||||
|
begin
|
||||||
|
If (Not Assigned(obj)) or (Obj^.objectclass<>StreamPrototypeDef) then
|
||||||
|
SEE_error__throw0(i,I^.TypeError,Nil);
|
||||||
|
Result:=PStreamObject(Obj)
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure StreamSize (i:PTSEE_interpreter; obj:PTSEE_object; thisobj:PTSEE_object; argc:Tcint; argv:PPTSEE_value;
|
||||||
|
res:PTSEE_value);cdecl;
|
||||||
|
|
||||||
|
Var
|
||||||
|
S : PStreamObject;
|
||||||
|
|
||||||
|
begin
|
||||||
|
S:=AsFile(I,ThisObj);
|
||||||
|
If (S^.Stream=Nil) then
|
||||||
|
SEE_error__throw0(i,PrivateData(I)^.Error,Nil);
|
||||||
|
SEE_SET_NUMBER(res,S^.Stream.Size);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure StreamWrite (i:PTSEE_interpreter; obj:PTSEE_object; thisobj:PTSEE_object; argc:Tcint; argv:PPTSEE_value;
|
||||||
|
res:PTSEE_value);cdecl;
|
||||||
|
|
||||||
|
Var
|
||||||
|
S : PStreamObject;
|
||||||
|
v : TSEE_Value;
|
||||||
|
t : string;
|
||||||
|
|
||||||
|
begin
|
||||||
|
S:=AsFile(I,ThisObj);
|
||||||
|
If (S^.Stream=Nil) then
|
||||||
|
SEE_error__throw0(i,PrivateData(I)^.Error,'File is closed');
|
||||||
|
if (ArgC=0) then
|
||||||
|
SEE_error__throw0(i,I^.RangeError,'Missing argument');
|
||||||
|
SEE_ToString(i,argv[0], @v);
|
||||||
|
T:=ValueToString(V);
|
||||||
|
If Length(T)>0 then
|
||||||
|
S^.Stream.Write(T[1],Length(T));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure StreamPosition (i:PTSEE_interpreter; obj:PTSEE_object; thisobj:PTSEE_object; argc:Tcint; argv:PPTSEE_value;
|
||||||
|
res:PTSEE_value);cdecl;
|
||||||
|
|
||||||
|
Var
|
||||||
|
S : PStreamObject;
|
||||||
|
v : TSEE_Value;
|
||||||
|
t : string;
|
||||||
|
|
||||||
|
begin
|
||||||
|
S:=AsFile(I,ThisObj);
|
||||||
|
If (S^.Stream=Nil) then
|
||||||
|
SEE_error__throw0(i,PrivateData(I)^.Error,'File is closed');
|
||||||
|
SEE_SET_NUMBER(res,S^.Stream.Position);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure StreamSeek (i:PTSEE_interpreter; obj:PTSEE_object; thisobj:PTSEE_object; argc:Tcint; argv:PPTSEE_value;
|
||||||
|
res:PTSEE_value);cdecl;
|
||||||
|
|
||||||
|
Var
|
||||||
|
S : PStreamObject;
|
||||||
|
v : TSEE_Value;
|
||||||
|
newpos : integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
S:=AsFile(I,ThisObj);
|
||||||
|
If (S^.Stream=Nil) then
|
||||||
|
SEE_error__throw0(i,PrivateData(I)^.Error,'File is closed');
|
||||||
|
if (ArgC=0) then
|
||||||
|
SEE_error__throw0(i,I^.RangeError,'Missing argument');
|
||||||
|
newpos:=SEE_ToUint32(i,argv[0]);
|
||||||
|
SEE_SET_NUMBER(res,S^.Stream.Seek(soFromBeginning,newpos));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure StreamRead (i:PTSEE_interpreter; obj:PTSEE_object; thisobj:PTSEE_object; argc:Tcint; argv:PPTSEE_value;
|
||||||
|
res:PTSEE_value);cdecl;
|
||||||
|
|
||||||
|
Var
|
||||||
|
S : PStreamObject;
|
||||||
|
r : PSEE_String;
|
||||||
|
j,maxlen : integer;
|
||||||
|
c : char;
|
||||||
|
|
||||||
|
begin
|
||||||
|
S:=AsFile(I,ThisObj);
|
||||||
|
If (S^.Stream=Nil) then
|
||||||
|
SEE_error__throw0(i,PrivateData(I)^.Error,'File is closed');
|
||||||
|
if (ArgC=0) then
|
||||||
|
maxlen:=1024
|
||||||
|
else
|
||||||
|
maxlen:=see_touint32(I,argv[0]);
|
||||||
|
r:=see_string_new(I,maxlen);
|
||||||
|
For j:=0 to maxLen-1 do
|
||||||
|
begin
|
||||||
|
S^.stream.Read(c,sizeOf(c));
|
||||||
|
SEE_string_addch(R,ord(c));
|
||||||
|
end;
|
||||||
|
SEE_SET_STRING(Res,r);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure StreamFree (i:PTSEE_interpreter; obj:PTSEE_object; thisobj:PTSEE_object; argc:Tcint; argv:PPTSEE_value;
|
||||||
|
res:PTSEE_value);cdecl;
|
||||||
|
|
||||||
|
Var
|
||||||
|
S : PStreamObject;
|
||||||
|
v : TSEE_Value;
|
||||||
|
t : string;
|
||||||
|
|
||||||
|
begin
|
||||||
|
S:=AsFile(I,ThisObj);
|
||||||
|
If (S^.Stream=Nil) then
|
||||||
|
SEE_error__throw0(i,PrivateData(I)^.Error,'File is closed');
|
||||||
|
FreeAndNil(S^.Stream);
|
||||||
|
SEE_SET_UNDEFINED(Res);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure StreamFinalize ( i:PTSEE_interpreter; p:pointer; closure:pointer);cdecl;
|
||||||
|
|
||||||
|
begin
|
||||||
|
FreeAndNil(PStreamObject(P)^.Stream);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure StreamConstruct (i:PTSEE_interpreter; obj:PTSEE_object; thisobj:PTSEE_object; argc:Tcint; argv:PPTSEE_value;
|
||||||
|
res:PTSEE_value);cdecl;
|
||||||
|
|
||||||
|
Var
|
||||||
|
P : PChar;
|
||||||
|
fm : Integer;
|
||||||
|
S : TStream;
|
||||||
|
Err : String;
|
||||||
|
R : PTSEE_Object;
|
||||||
|
|
||||||
|
begin
|
||||||
|
SEE_parse_args(i,argc,argv,'Z|i',@p,@fm);
|
||||||
|
If (P=Nil) then
|
||||||
|
SEE_error__throw0(i,I^.RangeError,'Missing argument');
|
||||||
|
Err:='';
|
||||||
|
try
|
||||||
|
S:=TFileStream.Create(strpas(p),fm);
|
||||||
|
except
|
||||||
|
On E : Exception do
|
||||||
|
Err:=E.Message;
|
||||||
|
end;
|
||||||
|
If (Err<>'') then
|
||||||
|
SEE_error__throw0(i,PrivateData(I)^.Error,PChar(Err));
|
||||||
|
R:=PTSEE_Object(SEE_malloc_finalize(I,SizeOf(TStreamObject),@StreamFinalize,Nil));
|
||||||
|
SEE_Native_init(PSEE_Native(R),I,StreamPrototypeDef,PrivateData(I)^.Prototype);
|
||||||
|
PStreamObject(r)^.Stream:=S;
|
||||||
|
SEE_SET_OBJECT(Res,R);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Procedure StreamInit(Interp : PSEE_Interpreter); cdecl;
|
||||||
|
|
||||||
|
Var
|
||||||
|
Stream,
|
||||||
|
StreamPrototype,
|
||||||
|
StreamError : PSee_object;
|
||||||
|
begin
|
||||||
|
// writeln('Initializing stream');
|
||||||
|
// Construct Stream.prototype object
|
||||||
|
// writeln('Creating Stream Prototype ');
|
||||||
|
StreamPrototype:=PSEE_object(SEE_malloc(Interp,SizeOf(TSTreamObject)));
|
||||||
|
See_native_init(PSEE_native(StreamProtoType),Interp,StreamPrototypeDef,interp^.Object_prototype);
|
||||||
|
PSTreamObject(StreamPrototype)^.stream:=Nil;
|
||||||
|
createJSFUnction(Interp,StreamPrototype,@StreamRead,GStreamRead,0);
|
||||||
|
createJSFUnction(Interp,StreamPrototype,@StreamWrite,GStreamWrite,0);
|
||||||
|
createJSFUnction(Interp,StreamPrototype,@StreamSize,GStreamSize,0);
|
||||||
|
createJSFUnction(Interp,StreamPrototype,@StreamPosition,GStreamPosition,0);
|
||||||
|
createJSFUnction(Interp,StreamPrototype,@StreamSeek,GStreamSeek,0);
|
||||||
|
createJSFUnction(Interp,StreamPrototype,@StreamFree,GStreamFree,0);
|
||||||
|
// writeln('Creating Stream');
|
||||||
|
// Construct Stream object
|
||||||
|
Stream:=PSEE_object(new_see_native);
|
||||||
|
See_native_init(PSEE_native(Stream),Interp,StreamObjectDef,interp^.Object_prototype);
|
||||||
|
CreateJSObject(Interp,Interp^.Global,GStreamStream,Stream);
|
||||||
|
CreateJSObject(Interp,Stream,GStreamprototype,StreamPrototype);
|
||||||
|
CreateJSNumber(Interp,Stream,GStreamfmCreate,fmCreate);
|
||||||
|
CreateJSNumber(Interp,Stream,GStreamfmOpenRead,fmOpenRead);
|
||||||
|
CreateJSNumber(Interp,Stream,GStreamfmOpenWrite,fmOpenWrite);
|
||||||
|
CreateJSNumber(Interp,Stream,GStreamfmOpenReadWrite,fmOpenReadWrite);
|
||||||
|
StreamError:=SEE_Error_make(interp, GSTreamError);
|
||||||
|
PrivateData(Interp)^.Stream:=STream;
|
||||||
|
PrivateData(Interp)^.Prototype:=StreamPrototype;
|
||||||
|
PrivateData(Interp)^.Error:=StreamError;
|
||||||
|
// writeln('Done initializing stream');
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure AllocateStreamStrings;
|
||||||
|
|
||||||
|
begin
|
||||||
|
GStreamRead:=SEE_intern_global('Read');
|
||||||
|
GStreamWrite:=SEE_intern_global('Write');
|
||||||
|
GStreamSeek:=SEE_intern_global('Seek');
|
||||||
|
GStreamSize:=SEE_intern_global('Size');
|
||||||
|
GStreamPosition:=SEE_intern_global('Position');
|
||||||
|
GStreamFree:=SEE_intern_global('Free');
|
||||||
|
GStreamfmCreate:=SEE_intern_global('fmCreate');
|
||||||
|
GStreamfmOpenRead:=SEE_intern_global('fmOpenRead');
|
||||||
|
GStreamfmOpenWrite:=SEE_intern_global('fmOpenWrite');
|
||||||
|
GStreamfmOpenReadWrite:=SEE_intern_global('fmOpenReadWrite');
|
||||||
|
GStreamStream:=SEE_intern_global('Stream');
|
||||||
|
GStreamError:=SEE_intern_global('Error');
|
||||||
|
GStreamPrototype:=SEE_intern_global('prototype');
|
||||||
|
end;
|
||||||
|
|
||||||
|
Function StreamInitModule : Integer; cdecl;
|
||||||
|
|
||||||
|
begin
|
||||||
|
// writeln('Initializing module');
|
||||||
|
StreamPrototypeDef:=new_SEE_objectclass;
|
||||||
|
With StreamPrototypeDef^ do
|
||||||
|
begin
|
||||||
|
_Class:='Stream';
|
||||||
|
get:=SEE_native_get;
|
||||||
|
put:=SEE_native_put;
|
||||||
|
canput:=SEE_native_canput;
|
||||||
|
hasproperty:=SEE_native_hasproperty;
|
||||||
|
Delete:=SEE_native_delete;
|
||||||
|
DefaultValue:=SEE_native_defaultvalue;
|
||||||
|
ENumerator:=SEE_native_enumerator;
|
||||||
|
Construct:=Nil;
|
||||||
|
Call:=Nil;
|
||||||
|
HasInstance:=Nil;
|
||||||
|
end;
|
||||||
|
StreamObjectDef:=new_SEE_objectclass;
|
||||||
|
With StreamObjectDef^ do
|
||||||
|
begin
|
||||||
|
_Class:='Stream';
|
||||||
|
get:=SEE_native_get;
|
||||||
|
put:=SEE_native_put;
|
||||||
|
get:=SEE_native_get;
|
||||||
|
put:=SEE_native_put;
|
||||||
|
canput:=SEE_native_canput;
|
||||||
|
hasproperty:=SEE_native_hasproperty;
|
||||||
|
Delete:=SEE_native_delete;
|
||||||
|
DefaultValue:=SEE_native_defaultvalue;
|
||||||
|
ENumerator:=SEE_native_enumerator;
|
||||||
|
Construct:=@StreamConstruct;
|
||||||
|
Call:=Nil;
|
||||||
|
HasInstance:=Nil;
|
||||||
|
end;
|
||||||
|
AllocateStreamStrings;
|
||||||
|
// writeln('Done Initializing module');
|
||||||
|
Result:=0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure RegisterStreamModule;
|
||||||
|
|
||||||
|
begin
|
||||||
|
// writeln('Registering stream module');
|
||||||
|
// StreamModule:=new_SEE_module;
|
||||||
|
With StreamModule do
|
||||||
|
begin
|
||||||
|
magic:=SEE_MODULE_MAGIC;
|
||||||
|
name:='Stream';
|
||||||
|
version:='1.0';
|
||||||
|
Index:=0;
|
||||||
|
Mod_init:=@StreamInitModule;
|
||||||
|
alloc:=@StreamAlloc;
|
||||||
|
init:=@StreamInit
|
||||||
|
end;
|
||||||
|
SEE_module_add(@StreamModule);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ ---------------------------------------------------------------------
|
||||||
|
Write(ln) module support
|
||||||
|
---------------------------------------------------------------------}
|
||||||
|
|
||||||
|
procedure WriteWrite (i:PTSEE_interpreter; obj:PTSEE_object; thisobj:PTSEE_object; argc:Tcint; argv:PPTSEE_value;
|
||||||
|
res:PTSEE_value);cdecl;
|
||||||
|
|
||||||
|
Var
|
||||||
|
a,C : Integer;
|
||||||
|
t : string;
|
||||||
|
v : TSEE_Value;
|
||||||
|
|
||||||
|
begin
|
||||||
|
if (ArgC=0) then
|
||||||
|
SEE_error__throw0(i,I^.RangeError,'Missing argument');
|
||||||
|
C:=0;
|
||||||
|
For A:=0 to Argc-1 do
|
||||||
|
begin
|
||||||
|
SEE_ToString(i,argv[a], @v);
|
||||||
|
T:=ValueToString(V);
|
||||||
|
If Length(T)>0 then
|
||||||
|
begin
|
||||||
|
Write(T);
|
||||||
|
C:=C+Length(T);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
SEE_SET_NUMBER(Res,C);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure WriteWriteln (i:PTSEE_interpreter; obj:PTSEE_object; thisobj:PTSEE_object; argc:Tcint; argv:PPTSEE_value;
|
||||||
|
res:PTSEE_value);cdecl;
|
||||||
|
|
||||||
|
|
||||||
|
begin
|
||||||
|
if (Argc>0) then
|
||||||
|
WriteWrite(i,obj,thisobj,argc,argv,res)
|
||||||
|
else
|
||||||
|
SEE_SET_NUMBER(Res,0);
|
||||||
|
Writeln;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Var
|
||||||
|
GWriteWrite : PSEE_STRING;
|
||||||
|
GWriteWriteln : PSEE_STRING;
|
||||||
|
|
||||||
|
Procedure WriteInit(Interp : PSEE_Interpreter); cdecl;
|
||||||
|
|
||||||
|
begin
|
||||||
|
// writeln('Initializing write');
|
||||||
|
createJSFUnction(Interp,Interp^.Global,@WriteWrite,GWriteWrite,1);
|
||||||
|
createJSFUnction(Interp,Interp^.Global,@WriteWriteln,GWriteWriteln,1);
|
||||||
|
// writeln('Done initializing write');
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure AllocateWriteStrings;
|
||||||
|
|
||||||
|
begin
|
||||||
|
GWriteWrite:=SEE_intern_global('write');
|
||||||
|
GWriteWriteln:=SEE_intern_global('writeln');
|
||||||
|
end;
|
||||||
|
|
||||||
|
Function WriteInitModule : Integer; cdecl;
|
||||||
|
begin
|
||||||
|
Result:=0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure RegisterWriteModule;
|
||||||
|
|
||||||
|
begin
|
||||||
|
// writeln('Registering write module');
|
||||||
|
// StreamModule:=new_SEE_module;
|
||||||
|
With WriteModule do
|
||||||
|
begin
|
||||||
|
magic:=SEE_MODULE_MAGIC;
|
||||||
|
name:='Write';
|
||||||
|
version:='1.0';
|
||||||
|
Index:=0;
|
||||||
|
Mod_init:=@WriteInitModule;
|
||||||
|
alloc:=Nil;
|
||||||
|
init:=@WriteInit
|
||||||
|
end;
|
||||||
|
AllocateWriteStrings;
|
||||||
|
SEE_module_add(@WriteModule);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
28
packages/libsee/examples/teststream.pp
Normal file
28
packages/libsee/examples/teststream.pp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
program teststream;
|
||||||
|
|
||||||
|
{$mode objfpc}
|
||||||
|
{$H+}
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, libsee, mod_stream;
|
||||||
|
|
||||||
|
Var
|
||||||
|
interp : TSEE_interpreter;
|
||||||
|
ainput : PSEE_INPUT;
|
||||||
|
res : TSEE_Value;
|
||||||
|
|
||||||
|
const
|
||||||
|
Program_text = 's = new Stream("test.txt",Stream.fmCreate); '+
|
||||||
|
's.Write("something"); '+
|
||||||
|
's.Free(); '+
|
||||||
|
'delete s;';
|
||||||
|
|
||||||
|
begin
|
||||||
|
see_init;
|
||||||
|
RegisterStreamModule;
|
||||||
|
SEE_interpreter_init(@interp);
|
||||||
|
ainput :=SEE_input_utf8(@interp, pchar(program_text));
|
||||||
|
See_global_eval(@interp,ainput,@res);
|
||||||
|
see_input_close(ainput);
|
||||||
|
end.
|
||||||
|
|
25
packages/libsee/examples/testwrite.pp
Normal file
25
packages/libsee/examples/testwrite.pp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
program testwrite;
|
||||||
|
|
||||||
|
{$mode objfpc}
|
||||||
|
{$H+}
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, libsee, mod_stream;
|
||||||
|
|
||||||
|
Var
|
||||||
|
interp : TSEE_interpreter;
|
||||||
|
ainput : PSEE_INPUT;
|
||||||
|
res : TSEE_Value;
|
||||||
|
|
||||||
|
const
|
||||||
|
Program_text = 'writeln("Hello, world!");';
|
||||||
|
|
||||||
|
begin
|
||||||
|
see_init;
|
||||||
|
RegisterWriteModule;
|
||||||
|
SEE_interpreter_init(@interp);
|
||||||
|
ainput :=SEE_input_utf8(@interp, pchar(program_text));
|
||||||
|
See_global_eval(@interp,ainput,@res);
|
||||||
|
see_input_close(ainput);
|
||||||
|
end.
|
||||||
|
|
23
packages/libsee/examples/tlibsee.pp
Normal file
23
packages/libsee/examples/tlibsee.pp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
program tlibsee;
|
||||||
|
|
||||||
|
uses libsee;
|
||||||
|
|
||||||
|
Var
|
||||||
|
Interp : TSEE_interpreter;
|
||||||
|
ainput : PSEE_INPUT;
|
||||||
|
res : TSEE_Value;
|
||||||
|
|
||||||
|
Const
|
||||||
|
Program_text = 'Math.sqrt(3 + 4 * 7)+9;';
|
||||||
|
|
||||||
|
begin
|
||||||
|
see_init;
|
||||||
|
SEE_interpreter_init(@Interp);
|
||||||
|
ainput :=SEE_input_utf8(@Interp, pchar(program_text));
|
||||||
|
See_global_eval(@interp,ainput,@res);
|
||||||
|
if (res._type=SEE_NUMBER) then
|
||||||
|
Writeln('Result is : ',res.u.number)
|
||||||
|
else
|
||||||
|
Writeln('Result is not a number');
|
||||||
|
see_input_close(ainput);
|
||||||
|
end.
|
42
packages/libsee/fpmake.pp
Normal file
42
packages/libsee/fpmake.pp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
{$ifndef ALLPACKAGES}
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
program fpmake;
|
||||||
|
|
||||||
|
uses fpmkunit;
|
||||||
|
|
||||||
|
Var
|
||||||
|
P : TPackage;
|
||||||
|
T : TTarget;
|
||||||
|
begin
|
||||||
|
With Installer do
|
||||||
|
begin
|
||||||
|
{$endif ALLPACKAGES}
|
||||||
|
|
||||||
|
P:=AddPackage('libsee');
|
||||||
|
{$ifdef ALLPACKAGES}
|
||||||
|
P.Directory:='libsee';
|
||||||
|
{$endif ALLPACKAGES}
|
||||||
|
P.Version:='2.5.1';
|
||||||
|
P.Author := 'David Leonard';
|
||||||
|
P.License := 'BSD style';
|
||||||
|
P.HomepageURL := 'http://www.adaptive-enterprises.com.au/~d/software/see/';
|
||||||
|
P.Email := 'leonard@users.sourceforge.net';
|
||||||
|
P.Description := 'Headers for the libSEE library (javascript engine)';
|
||||||
|
P.NeedLibC:= true; // true for headers that indirectly link to libc?
|
||||||
|
|
||||||
|
P.SourcePath.Add('src');
|
||||||
|
P.IncludePath.Add('src');
|
||||||
|
|
||||||
|
T:=P.Targets.AddUnit('libsee.pas');
|
||||||
|
|
||||||
|
P.ExamplePath.Add('examples');
|
||||||
|
P.Targets.AddExampleUnit('mod_stream.pp');
|
||||||
|
P.Targets.AddExampleProgram('tlibsee.pp');
|
||||||
|
P.Targets.AddExampleProgram('testwrite.pp');
|
||||||
|
P.Targets.AddExampleProgram('teststream.pp');
|
||||||
|
|
||||||
|
{$ifndef ALLPACKAGES}
|
||||||
|
Run;
|
||||||
|
end;
|
||||||
|
end.
|
||||||
|
{$endif ALLPACKAGES}
|
1072
packages/libsee/src/libsee.pas
Normal file
1072
packages/libsee/src/libsee.pas
Normal file
File diff suppressed because it is too large
Load Diff
189
packages/libsee/src/libseewrap.c
Normal file
189
packages/libsee/src/libseewrap.c
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
#include <see/see.h>
|
||||||
|
|
||||||
|
|
||||||
|
int SEE_help_Global_eval(interp, input, res)
|
||||||
|
struct SEE_interpreter *interp;
|
||||||
|
struct SEE_input *input;
|
||||||
|
struct SEE_value *res;
|
||||||
|
{
|
||||||
|
SEE_try_context_t c;
|
||||||
|
|
||||||
|
|
||||||
|
SEE_TRY(interp,c) {
|
||||||
|
SEE_Global_eval (interp, input, res);
|
||||||
|
}
|
||||||
|
if (SEE_CAUGHT(c)) {
|
||||||
|
SEE_VALUE_COPY(res, SEE_CAUGHT(c));
|
||||||
|
return 1;
|
||||||
|
} else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_value * SEE_help_CAUGHT (c)
|
||||||
|
struct SEE_try_context * c;
|
||||||
|
{
|
||||||
|
return (SEE_CAUGHT(*c));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SEE_help_THROW (interp,v)
|
||||||
|
struct SEE_interpreter *interp;
|
||||||
|
struct SEE_value * v;
|
||||||
|
{
|
||||||
|
SEE_THROW(interp,v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SEE_help_RETHROW (interp,c)
|
||||||
|
struct SEE_interpreter *interp;
|
||||||
|
struct SEE_try_context * c;
|
||||||
|
{
|
||||||
|
SEE_RETHROW(interp,* c);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SEE_help_DEFAULT_CATCH (interp,c)
|
||||||
|
struct SEE_interpreter *interp;
|
||||||
|
struct SEE_try_context * c;
|
||||||
|
{
|
||||||
|
SEE_DEFAULT_CATCH(interp,* c);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_interpreter * new_SEE_interpreter()
|
||||||
|
{
|
||||||
|
struct SEE_interpreter *interp;
|
||||||
|
|
||||||
|
interp = SEE_NEW(NULL, struct SEE_interpreter);
|
||||||
|
SEE_interpreter_init(interp);
|
||||||
|
return interp;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_value * new_SEE_value ()
|
||||||
|
{
|
||||||
|
struct SEE_value * p;
|
||||||
|
p = SEE_NEW(NULL, struct SEE_value);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_objectclass * new_SEE_objectclass ()
|
||||||
|
{
|
||||||
|
struct SEE_objectclass * p;
|
||||||
|
p = SEE_NEW(NULL, struct SEE_objectclass);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_object * new_SEE_object ()
|
||||||
|
{
|
||||||
|
struct SEE_object * p;
|
||||||
|
p = SEE_NEW(NULL, struct SEE_object);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_enumclass * new_SEE_enumclass ()
|
||||||
|
{
|
||||||
|
struct SEE_enumclass * p;
|
||||||
|
p = SEE_NEW(NULL, struct SEE_enumclass);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_enum * new_SEE_enum ()
|
||||||
|
{
|
||||||
|
struct SEE_enum * p;
|
||||||
|
p = SEE_NEW(NULL, struct SEE_enum);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_native * new_SEE_native ()
|
||||||
|
{
|
||||||
|
struct SEE_native * p;
|
||||||
|
p = SEE_NEW(NULL, struct SEE_native);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_scope * new_SEE_scope ()
|
||||||
|
{
|
||||||
|
struct SEE_scope * p;
|
||||||
|
p = SEE_NEW(NULL, struct SEE_scope);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_inputclass * new_SEE_inputclass ()
|
||||||
|
{
|
||||||
|
struct SEE_inputclass * p;
|
||||||
|
p = SEE_NEW(NULL, struct SEE_inputclass);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_input * new_SEE_input ()
|
||||||
|
{
|
||||||
|
struct SEE_input * p;
|
||||||
|
p = SEE_NEW(NULL, struct SEE_input);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_traceback * new_SEE_traceback ()
|
||||||
|
{
|
||||||
|
struct SEE_traceback * p;
|
||||||
|
p = SEE_NEW(NULL, struct SEE_traceback);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_context * new_SEE_context ()
|
||||||
|
{
|
||||||
|
struct SEE_context * p;
|
||||||
|
p = SEE_NEW(NULL, struct SEE_context);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_growable * new_SEE_growable ()
|
||||||
|
{
|
||||||
|
struct SEE_growable * p;
|
||||||
|
p = SEE_NEW(NULL, struct SEE_growable);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_module * new_SEE_module ()
|
||||||
|
{
|
||||||
|
struct SEE_module * p;
|
||||||
|
p = SEE_NEW(NULL, struct SEE_module);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_string * new_SEE_string ()
|
||||||
|
{
|
||||||
|
struct SEE_string * p;
|
||||||
|
p = SEE_NEW(NULL, struct SEE_string);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_stringclass * new_SEE_stringclass ()
|
||||||
|
{
|
||||||
|
struct SEE_stringclass * p;
|
||||||
|
p = SEE_NEW(NULL, struct SEE_stringclass);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_system * new_SEE_system ()
|
||||||
|
{
|
||||||
|
struct SEE_system * p;
|
||||||
|
p = SEE_NEW(NULL, struct SEE_system);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_throw_location * new_SEE_throw_location ()
|
||||||
|
{
|
||||||
|
struct SEE_throw_location * p;
|
||||||
|
p = SEE_NEW(NULL, struct SEE_throw_location);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SEE_try_context * new_SEE_try_context ()
|
||||||
|
{
|
||||||
|
struct SEE_try_context * p;
|
||||||
|
p = SEE_NEW(NULL, struct SEE_try_context);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_SEE_struct(p)
|
||||||
|
void * p;
|
||||||
|
{
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user