Results 1 to 10 of 10

Thread: delphi programming. (Scripting Language)

  1. #1

    delphi programming. (Scripting Language)

    i'm currently working on a rpg maker and have finished the tile engine.

    I was wondering if anyone knew how to create a scripting language in delphi or can give a sample code to start me off.

    The scripting language will help load the tiles, and control npc and stuff.

    Thank you if someone can help me.

  2. #2

    delphi programming. (Scripting Language)

    Hi

    If you are after a good pascal scripting lanugage, try te Pascal Script from Rem Objects http://www.remobjects.com/page.asp?i...-EEBBE7E302E6}

    It used to be Innerfuse Pascal Script, but the author went to work for Rem Objects and took the software with him. It's a nice system, allows you to compile scripts and use Delphi objects in your scripts. All in all a good solution.

    Dean
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  3. #3
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    delphi programming. (Scripting Language)

    Hmm... is there a Free Pascal capable solution aswell?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  4. #4

    delphi programming. (Scripting Language)

    The scripting system works under FPC I've tested it.

    It does need a few changes here and there to get it compiling but the changes aren't too complicated.
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  5. #5

    delphi programming. (Scripting Language)

    It works with freepascal and, with some limitations, I installed it in Lazarus too. Indeed you can install 4 components only (PSScript, PSScriptDebugger, PSDllPlugin, PSScriptExtension), because the others are heavyly based on vcl and a porting is very hard.
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  6. #6

    delphi programming. (Scripting Language)

    I don't use the components, you can skip that a just go straight to the compiler and run time classes. It's a little more work , but you get around having to convert the components.

    it's nice an quick too
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  7. #7
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    delphi programming. (Scripting Language)

    Can you use the non VCL objects as is or is there any conversion neccessary. I am trying to find a nice pascal scripting colution for my games - currently I'm using DWS (which needs VCL).

    If you have some nice examples of registering call back functions and procedures I'd appreciate it (I vahe them nicely packeged in a procedure now).
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  8. #8

    delphi programming. (Scripting Language)

    Another Scripting solution I have looked into is JavaScript ( AKA SpiderMonkey ). There are some Delphi bindings out there ( http://delphi.mozdev.org/ ) and they should work on Linux as well. Almost everyone knows JavaScript due to it being used pervasivly on in WebPage and the Mozilla browser.

    Anyway just another option.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  9. #9

    delphi programming. (Scripting Language)

    The non VCL components derive from TObject so it can work without the VCL. Note that you do need to mess around with the units to get them to compile under FPC as they haven't quite got the IFDEF's right.

    Running scripts is in two stages, first you compile the script , then you execute it. The compile stage can be done as a pre process so you can distribute only compiled scripts with your application.

    There is an example of running a compiled script, the script and thje compiler. It assumes that the Pascal Script units are in you library path.

    Hope it helps

    Dean


    Testbed to run the code

    [pascal]
    program testbed;
    {$APPTYPE CONSOLE}
    uses
    SysUtils,
    Classes,
    Dialogs,
    uPSRuntime,
    uPSUtils,
    uPSCompiler;



    var Exec: TPSExec;
    s: TStringStream;
    fs: TFileStream;


    procedure Debug_LogMessage(const s: string);
    begin
    Writeln(s);
    end;
    function Debug_GetInput: string;
    begin
    Result := InputBox('Debug_GetInput','GetInput','test');
    end;

    begin
    Exec := TPSExec.Create;
    s := TStringStream.Create('');
    try
    Exec.RegisterDelphiFunction(@Debug_LogMessage, 'DEBUG_LOGMESSAGE', cdRegister);
    Exec.RegisterDelphiFunction(@Debug_GetInput, 'DEBUG_GETINPUT', cdRegister);

    fs := TFileStream.Create(ParamStr(1), fmOpenRead);
    try
    s.CopyFrom(fs, 0);
    finally
    fs.Free;
    end;
    if not Exec.LoadData(s.DataString) then
    begin
    Writeln(Exec.ExceptionString);
    Exit;
    end;
    Exec.RunScript;
    finally
    s.Free;
    Exec.Free;
    Readln;
    end;
    end.
    [/pascal]

    Here is the test script

    [pascal]
    var t: string;
    i: integer;
    begin
    t := Debug_GetInput;
    for i := 0 to 100 do
    begin
    Debug_LogMessage(t);
    end;
    end.
    [/pascal]

    This is the compiler
    [pascal]
    program compiler;

    uses
    SysUtils, Dialogs, Classes,
    uPSUtils,
    uPSCompiler,
    uPSPreProcessor,
    uPSRuntime;

    var Compiler: TPSPascalCompiler;
    Data: string;
    Script: TStringList;
    CompiledScript: TStringStream;
    idx: Integer;


    function OnUses(Sender: TPSPascalCompiler; const Name: string): Boolean;
    begin
    Writeln('OnUses');
    Result := False;
    if Name = 'SYSTEM' then
    begin
    Sender.AddDelphiFunction('procedure Debug_LogMessage(const s: string)');
    Sender.AddDelphiFunction('function Debug_GetInput: string');
    Result := True;
    end;
    end;


    function OnExportCheck(Sender: TPSPascalCompiler; Proc: TPSInternalProcedure; const ProcDecl: string): Boolean;
    begin
    Result := True;
    end;

    begin
    Script := TStringList.Create;
    Script.LoadFromFile(ParamStr(1));
    Compiler := TPSPascalCompiler.Create;
    try
    Compiler.OnUses := OnUses;
    Compiler.OnExportCheck := OnExportCheck;
    Compiler.AllowNoBegin := True;
    Compiler.AllowNoEnd := True; // AllowNoBegin and AllowNoEnd allows it that begin and end are not required in a script.
    if not Compiler.Compile(Script.Text) then // Compile the Pascal script into bytecode.
    begin
    // You could raise an exception here.
    for idx := 0 to Compiler.MsgCount-1 do
    begin
    Writeln(Compiler.Msg[idx].MessageToString);
    end;
    Exit;
    end;
    Compiler.GetOutput(Data); // Save the output of the compiler in the string Data.
    CompiledScript := TStringStream.Create(Data);
    try
    with TFileStream.Create(ParamStr(2), fmCreate or fmOpenWrite) do
    begin
    try
    CopyFrom(CompiledScript, 0);
    finally
    Free;
    end;
    end;
    finally
    CompiledScript.Free;
    end;
    finally
    Compiler.Free;
    Script.Free;
    end;
    end.
    [/pascal]
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  10. #10
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    delphi programming. (Scripting Language)

    Thanks - this is exactly what I need This is one of the last things stopping my move over to FreePascal at home, now if only they can drop the size of the exes!
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •