Results 1 to 9 of 9

Thread: "Scripting" language

  1. #1

    "Scripting" language

    He guys,

    Still working on QDFPS (http://www.pascalgamedevelopment.com...p?14893-Qdfps/) and I wrote a little "scripting" language for this. The only thing you can actually do is set variables and execute procedures with up to 5 parameters so its pretty limited I use it for my console and for map scripts to load and set things while a map is loading. Syntax is a mix between pascal and c and there are and it supports booleans, integers, floats and strings as parameters. Strings however have some limitations which for me is fine since I only use them for paths. The code should be pretty self explanatory and it comes with a testbed. I though some other people might find it usefull.

    Luuk
    Attached Files Attached Files

  2. #2
    How about using PascalScript by RemoteObjects (might mess up name)? You'd be able to expose procedures, types and variables to scripts and scripts would be coded with Pascal with which you are familiar with?

    Granted, they are VCL/LCL-based, but you can create them in code or if you prefer visual approach, place them visually on data module and then create this data module (from my understanding all are non-visual).

  3. #3
    I actually used this for some of my previous projects. Works great but for what I need for this project its a bit to heavy.

  4. #4
    Ah, okay. If that's the case... I just thought you don't know about PascalScript.

  5. #5
    I redid the parsing of the commands:

    - 60% faster parsing
    - Better syntax checking
    - Less and cleaner code
    - Fix a load of small bugs

    Regards,
    Luuk
    Attached Files Attached Files

  6. #6
    Hi Luuk, nice work

    I just looked at your code, rather neat.

    I have coded an extra Params() function for a variable amount of params that you could use instead of using the multiple functions if you wish...

    Code:
    function Params(const p: array of TParam): TParams; overload;
    
    
    implementation
    
    {...}
    
    
    function Params(const p: array of TParam): TParams; overload;var
      i: Integer;
    begin
      setLength(Result,Length(p));
      for i := 0 to High(p) do
        result[i] := p[i];
    end;
    You would use it like so (adding any amount of params to the 'list' between the '[' and ']'):

    Code:
    Command('SetValues', @SetValues, Params([p(PT_BOOL), p(PT_INT), p(PT_FLOAT), p(PT_STR)]));
    cheers,
    Paul

  7. #7
    Thank paul Made the following changes.

    - Unlimited parameters (Thanks to Pauls suggestion.)
    - Again less and cleaner code
    - Streamlined the error messaging

    I think the code is as streamlined and optimised as can be now so this is probably the final version

    Regards,
    Luuk
    Attached Files Attached Files

  8. #8
    There are some little things you could clean, that compiler still tells

    ignore? - scripting.pas(81,27) Hint: Local variable "c" does not seem to be initialized
    *see below 1) - scripting.pas(212,16) Warning: Local variable "str" does not seem to be initialized
    ignore? - scripting.pas(238,36) Hint: Local variable "c" does not seem to be initialized
    remove - scripting.pas(133,3) Note: Local variable "com" not used
    remove - Unit1.pas(36,23) Hint: Parameter "params" not used
    remove - Unit1.pas(41,29) Hint: Parameter "params" not used
    ignore? - Unit1.pas(63,33) Hint: Local variable "freq" does not seem to be initialized
    ignore? - Unit1.pas(64,32) Hint: Local variable "start" does not seem to be initialized
    ignore? - Unit1.pas(66,31) Hint: Local variable "stop" does not seem to be initialized
    remove - Unit1.pas(6,12) Hint: Unit "messages" not used in Unit1
    remove - ScriptingTest.lpr(12,15) Warning: Symbol "MainFormOnTaskBar" is not portable

    1) Line is str := str + script[i]; where str was not initialized (meaning str := ''; ). It could be that compiler nulls dynamic arrays and strings, but i'm not sure if it does on all possible fpc compilers and their settings.

    Lots of 'Local variable X does not seem to be initialized' could be rid of by changing "var" to "out", but i just recently read that fpc might allocate that parameter for itself, instead of using the parameter reference... That might slow down performance slightly if so.
    edit: In my test app var, out and pointer perform pretty much the same. I had 1 parameter record with 1kb data.
    Last edited by User137; 24-07-2013 at 08:46 PM.

  9. #9
    Hint: Local variable "c" does not seem to be initialized
    This usually happens when you are accesing your variable only from within if statements, case statements and while loops. The reason for this is that under certain circumstances theese variables arent even used so compiler optimization sometimes doesn't even initalize them which can result in AccesViolation or weird values of theese varaibles.
    I usually circumvent this by seting some default value to theese variables in the first few lines of the method in which they are declared.

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
  •