Results 1 to 8 of 8

Thread: "Scripting"

  1. #1

    "Scripting"

    Hi guys!

    I want to create a very very basic scripting system, all I want to do, is to run procedures/functions with parameters from a file at runtime.

    IE: the following line in a text file would execute "procedure Test(X: integer);" in the main app.

    Test(145)

    The thing is, I have no idea what-so-ever when it comes to how to actually do somthing like this. So I'm just fishing around for some tips
    BK - we.create (tm)

  2. #2

    "Scripting"

    I don't think you need to take the usual approach at writing a scripting system as what you want to do isn't really executing expressions and stuff like that.

    If you say that all procedure calls have this format:
    IDENTIFIER - BRACKET - LIST OF PARAMETERS - BRACKET - SEMICOLON
    then all you have to do is go through each line of your text file, and parse it. So you'd copy from the beginning of a line up to the first opening bracket (this gives you the name of the procedure), then you'd move on up to the first comma and you'd have the first parameter, etc.

    Now calling procedures in your main program is a whole different matter. I'd recommend encapsulating the parser into an object. The object could have an event that gets called for each procedure call in your text file. So the procedure handling that event could then call the procedures in your main program.
    You can also create a list/array of procedures like this:

    type TMyProcedure = procedure(Param1: ParamType; Param2: ParamType2...);

    type TMyProcedureItem = record
    Proc: TMyProcedure;
    Name: string;
    end;

    MyProcedures: array[1..10] of TMyProcedureItem;

    It's all up to you. But it should be easy enough to write.
    Hope that helped.
    Ask me about the xcess game development kit

  3. #3

    "Scripting"

    If your functions are methods of a class, rather than free-standing ones, you could look at TObject.MethodAddress
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  4. #4

    "Scripting"

    Thank you to the both of you for the extremly quick replies

    I've written some very nasty test code based on the ideas I got from reading Harry's post and the article at Delphi3D.

    Again, thanks guys
    BK - we.create (tm)

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

    "Scripting"

    Also DWS at its most simple is exactly what you want to do.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  6. #6

    "Scripting"

    cairnswm: I tried it out yesterday, (found a link when searching the forums) but I wanted somthing non-vcl
    BK - we.create (tm)

  7. #7

    "Scripting"

    [quote="Mrwb"]cairnswm: I tried it out yesterday, (found a ]
    There is ifps3. It doesnt even use Borland's classes unit to my knowlage.

    link

  8. #8

    "Scripting"

    ggs: thanks, looks very neat, I'll check it out later
    BK - we.create (tm)

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
  •