Poll: Rate this

Be advised that this is a public poll: other users can see the choice(s) you selected.

Results 1 to 11 of 11

Thread: LAPE Basics and modifications [Guide/Tut]

  1. #1
    Join Date
    Jan 2012
    Location
    127.0.0.1
    Posts
    702
    Mentioned
    11 Post(s)
    Quoted
    76 Post(s)

    Lightbulb LAPE Basics and modifications [Guide/Tut]

    Basic Tutorial/Guide to Lape :P
    Examples from @nielsie95's Thread Here
    Lape is 95% similar to simba, but with a few nice changes, but I will go over the basics again.

    Summary:
    Faster,
    Better Parsing
    More Versatile across platforms
    Much larger potential
    Does not work with current srl lib, but is hopefully going to work in Simba 1.0 with SRL 6
    Same method for Including for compiler

    current issues -
    Code:
    Giving variables a value in the declaration (i.e. var t := (getSystemTime() + 5000)) will cause everything after that line to disappear from the function list.
    o Using “for var i := 0 to 9 do” does the same as above.
    o When {$include_once file.simba} is used to include the same file more than once, it’s functions appears multiple times on the function list. This only applies if the file is included in two separate files. To recreate, download this package and open c.simba. Search “example” in the function list search bar, and you will see multiple versions of the same function.
    o A type function should include the type in the function list. For example, instead of showing “setAngle”, the function list will show “TRSMinimap.setAngle”
    When there is a compiling error in Lape, Simba doesn’t jump to that line or open the file that contains the error, it just prints the error in the debug box.


    Your Base Types:

    Integers: Normal whole numbers just like in PS

    This splits up into (Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64) Lengths of how long they are, shorter length integers are faster to compute and take up less memory but cant store as much data

    Floats: decimal Places


    -Single - (4-byte) single-precision floating-point numbers ranging in value from -3.4028235E+38 through -1.401298E-45 for negative values and from 1.401298E-45 through 3.4028235E+38 for positive values. Single-precision numbers store an approximation of a real number.

    -Double - 32 Bit data type

    -Extended - 40-bit "extended precision" format

    -Currency - 4 Decimal Places

    Char(acters)
    -Ansi - this is the standard list of 217 main characters
    -Wide - A wide character is a computer character datatype that generally has a size greater than the traditional 8-bit character

    Strings - enclosed in apostrophies : 'hello'

    -Short strings - these are the basic ascii character based strings

    -ANSI -a series of characters made up of ANSI Chars

    -WIDE -a series of characters made up of WIDE Chars

    -UNICODE -a series of characters made up of UNICODE Chars

    Variants - a variable that can contain anything

    Arrays- a container for different variables, can have different dimensions

    Record- This complex data type corresponds to a row in a table. Each record consist of fields that form the columns of the table. A record is typically used to hold information about a fixed number of properties.
    Simba Code:
    type
      TPoint = record
        x, y: Integer;
      end;

    const
      tp: TPoint = [1,2];

    var
      t: TPoint;
    begin
      t := tp;
      t := [,2];
      WriteLn(t, ' :: ', tp);
    end;

    Assignments are now expressions, so you can now assign variables whist assigning a value to another variable at the same time:
    Simba Code:
    var
      a, b: Integer;
    begin
      a := b := 0;
      a := 1 + (b := 2);
      WriteLn('a: ', a, ' b: ', b);
    end;

    Enums - are a data type consisting of a set of named values called elements, members or enumerators of the type. The Boolean type, for example is often a pre-defined enumeration of the values FALSE and TRUE. Many languages allow the user to define new enumerated types. ( possibly fits in with records)

    Pointers - Defined by @procedure sets a procedure to a variable/ in memory sense, it physically directs the counter to the set memory address.
    Pointers
    Simba Code:
    var
      a: Integer;
      b: ^Integer;
    begin
      a := 2;
      b := @a;
      b^ := 3;
      WriteLn(a);
    end;


    Function Pointers- points towards a function and may be able to pass parameters
    Simba Code:
    Var
    thisvar := Function();
    Function Reply() : Boolean;
    Begin
    Writeln('Hello');
    Exit(True);
    end;
    Begin
      thisvar := @reply;
      If thisvar() then
        Writeln('bye');
    end;
    Operations:

    :=
    Your definition operator for assigning data to variables

    Whats New:
    -Assigning default values.

    Simba Code:
    procedure test(a: Integer = 1; b: string = 'a');
    begin
      WriteLn(a, ' -> ', b);
    end;

    begin
      test;
      test(,'hoi');
      test(2);
    end;

    As said above, assignments are now also operators and multiple assignments can be made every "line"

    =
    Equals operator, will return 1 if the 2 values are equal - simple action handled by the Arithmetic logic Unit on your cpu

    <>
    Not Equals, opposite value of equlas operator

    >
    bigger than, returns 1 if left value is larger than right value. returns 0 if equal or below

    >=
    Bigger or equal to, Like ">" but returns 1 if equal

    <
    smaller than - ref to ">"

    <=
    smaller or equal to, Like "<" but returns 1 if equal

    @
    returns the address of a variable, or of a function, procedure, or method; that is, @ constructs a pointer to its operand.

    ----Math Operators----

    ^ or **
    Power operator like the function pow(base,exponent)

    +,-,*,/
    Basic calculation operators

    Mod, i.e a:= 6 mod 4 ; a would = 2 (returns the remainder)


    Logic Operators

    Boolean operators
    And
    OR
    XOR
    NOT

    Bitwise Operators
    SHL
    SHR

    more info on bitwise operators:http://compsci.ca/v3/viewtopic.php?t=9893


    More Features:

    Overloading Functions

    Function overloading or method overloading that allows creating several methods with the same name which differ from each other in the type of the input and the output of the function. It is simply defined as the ability of one function to perform different tasks.
    (this also works for imported functions)
    Simba Code:
    procedure Hoi(Name: string); overload;
    begin
      WriteLn('Hoi ', Name);
    end;

    procedure Hoi; overload;
    begin
      Hoi('folks');
    end;

    begin
      Hoi;
    end;

    Overriding Functions:
    This is when you what a certain function to do something else or give it a different execution pattern.
    Simba Code:
    function IntToStr(i: Int64): string; override;
    begin
      Result := 'int ' + inherited;
    end;

    begin
      Writeln(IntToStr(42));
    end;

    Else Clauses for while/ for loops:
    You can now apply the else clause as shown below:
    Simba Code:
    begin
      for 1 to -1 with 2 do
        WriteLn('Looping')
      else
        WriteLn('No loop.. Aww!');

      while False do
        {nothing}
      else
        Writeln('No loop again. Jeez.');
    end;



    Passing Values to exit statements:
    Exit(Result)/Continue(Depth)/Break(Depth)
    Simba Code:
    function Test: Integer;
    var
      i: Integer;
    begin
      for i := 1 to 10 do
      begin
        WriteLn('i = ', i);
        repeat
          if (i < 3) then
            Continue(2)
          else
            Break(2);
        until False;

        WriteLn('Out of the loop');
      end;
      Exit(-1);
    end;

    begin
      Test;
    end;



    Joining Records: nice feature
    Simba Code:
    type
      TRGBRecord = packed record
         R, G, B: Byte;
      end;
      TRGB = union
        Color: Integer;
        RGB: TRGBRecord;
      end;

    var
      c: TRGB;
    begin
      c.Color := 16777215 {clWhite};
      WriteLn('R: ', c.RGB.R, ' G: ', c.RGB.G, ' B: ', c.RGB.B);
    end;


    Untyped parameters
    This is very useful in some awkward to program places
    Simba Code:
    procedure Untyped(const x);
    begin
      WriteLn(Integer(x));
    end;

    var
      i = 1;
      a = [1, 2, 3, 4];
    begin
      Untyped(i);
      Untyped(a);
    end;

    Loose Syntaxing
    Simba Code:
    {$X+}

    WriteLn('hoi!');

    begin
      var i = 0;
      for var a := 0 to 2 do
        i := i + a * 2;
      WriteLn(a);
    end;

    Type Functions:
    Type functions
    Simba Code:
    function Integer.Next: Integer;
    begin
      Result := Self + 1;
    end;

    begin
      WriteLn(2.Next);
    end;

    Will be adding to this when i have time.

  2. #2
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,164
    Mentioned
    26 Post(s)
    Quoted
    433 Post(s)

  3. #3
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Thanks rep++ this is needed to push lape

  4. #4
    Join Date
    May 2013
    Posts
    23
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    nice tutorial enslaved. I have a few questions.
    Is it possible to override the default operators for a "type" ive defined, for example '<', '='?
    is it possible to have this sort of referencing?
    Code:
    type Person= record
    name: String;
    age: String;
    Parent: ^Person;
    end;
    Last edited by ActualNoob; 06-10-2013 at 11:58 AM.

  5. #5
    Join Date
    Aug 2013
    Posts
    41
    Mentioned
    0 Post(s)
    Quoted
    16 Post(s)

    Default

    Great, but what's the syntax for declaring/using Enums? Are arrays always pointers as in C/Java or no?

  6. #6
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Be careful when writing type functions. Making something like this could potentially mess up your script:
    Simba Code:
    procedure Integer.setNext();
    begin
      self := self + 1;
    end;

    var
      a := 2;

    begin
      writeLn(1);  // 1
      writeLn(a);  // 2
      a.setNext(); // a = 3
      writeLn(a);  // 3
      3.setNext(); // 3 = 4
      writeLn(3);  // 4
    end;

  7. #7
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    GREAT

    minus comparing lape to simba :P

  8. #8
    Join Date
    Sep 2008
    Posts
    754
    Mentioned
    8 Post(s)
    Quoted
    275 Post(s)

    Default

    This works really well with Simba 1.0, the oldschool include now won't compile with simba 1.0 tho

    great guide!

  9. #9
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    I tried your examples for both Function Pointers as well as Loose Syntaxing, both gave compile errors. Are you sure this information is accurate?...

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  10. #10
    Join Date
    Oct 2012
    Location
    Porto, Portugal
    Posts
    218
    Mentioned
    0 Post(s)
    Quoted
    42 Post(s)

    Default

    Thanks! Was waiting for this.

  11. #11
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    I tried your examples for both Function Pointers as well as Loose Syntaxing, both gave compile errors. Are you sure this information is accurate?...
    Because a lot of the information is missing or in-accurate..


    @OP..

    Float aka a Single is a 32-bit data type.. Why would a double be 32 then if it is guaranteed to be "double" the size of a float?

    A double is a 64-bit data type (In Simba x32-x64).
    An extended is 10 bytes in size and is an 80-bit data type.


    In lape you can do:

    Simba Code:
    begin
      writeln(sizeof(Double) * 8);  //it would print 64.
      writeln(sizeof(Single) * 8);  //it would print 32.
      writeln(sizeof(Integer) * 8); //it would print 32.
      writeln(sizeof(Extended) * 8); //it would print 80.
      writeln(sizeof(Int64) = sizeof(Double)); //Will print true because both are 64-bit data types.
    end.


    Missed an example for enums which would be:

    Simba Code:
    type Interface = (CHAT, INVENTORY, SETTINGS, MINIMAP);


    Procedure Switch(I: Interface);
    Begin
      Case I Of
        CHAT: writeln('Chat Interface');
        INVENTORY: writeln('Inventory Interface');
        SETTINGS: writeln('Settings Interface');
        MINIMAP: writeln('Minimap Interface');
      end;
    End;

    begin
      Switch(Interface.CHAT);  //Enum via Non-Global Namespace access.
      Switch(Settings);   //Global Namespace enum access.
      Switch(1);          //Non-strongly typed enum. Integer can be implicitly casted to an enum.
      writeln(Ord(Interface.CHAT));
    end.

    Pointers - Defined by @procedure sets a procedure to a variable/ in memory sense, it physically directs the counter to the set memory address.
    Isn't right :S.. Not sure what counter but that isn't what a pointer does. A pointer holds the memory address of an object, record, procedure, function, variable, etc.. Anything.. A pointer also takes up space on the stack in order to hold the address.

    You can find out how many bytes it takes up by doing:
    Simba Code:
    writeln(sizeof(Pointer));


    Next, this example below is incorrect.. It is missing the return type of the function pointer.. It's also assigning to a variable of unknown type instead of declaring that variable of func-pointer type.
    Simba Code:
    Var
      thisvar := Function();  //This line is wrong.. Cannot assign thisvar to an anonymous function aka a Lambda.. Also declaration of the function pointer is incorrect..
    Function Reply() : Boolean;
    Begin
      Writeln('Hello');
      Exit(True);
    End;

    Begin
      thisvar := @reply;
      If thisvar() then
        Writeln('bye');
    End;


    It should be:

    Simba Code:
    Var
      thisvar: Function(): Boolean; //Function return type fixed and the := is changed to semi-colon.
    Function Reply() : Boolean;
    Begin
      Writeln('Hello');
      Exit(True);
    End;

    Begin
      thisvar := @reply;
      If thisvar() then
        Writeln('bye');
    End;

    @ constructs a pointer to its operand.
    No it does not.. @ only gives the address of its operand. Simply using @ alone does nothing. Nothing points to anything there. You need to do something with the address it gives you. Maybe assign it to a pointer or pass it to a function or dereference it.


    Math Operators ^ or ** acts like pow(X, Exponent)
    No it does not.. ^ operator only does that in C or C++ or other languages.. In Pascal, that ^ operator means to either create a pointer or to derefence a pointer..

    Simba Code:
    var
      Ptr: ^Integer; //The ^ before the Integer means it is a pointer to an integer.
    begin
      Ptr^ := 3;  //The ^ after the variable name means to dereference the pointer.. aka retrieve the value being pointed to..
                  //Assigning to a dereferenced pointer changes the value being pointed to.
    end.

    That is it.. no power operator. Also, in the most recent Simba, ** as power operator is broken.

    Example:
    Simba Code:
    begin
      writeln((2 ** 2)); //Exception in Script: Operator "Power" not compatible with types at line 2, column 14
    end.


    Not, And, Or, XOR are BITWISE operators.. Or, And, and Not operators can be both logical and bitwise.

    Example:
    Simba Code:
    Function IsOdd(Value: Integer): Boolean;
    Begin
      Result := (Value And 1); //Bitwise And.
    End;

    Begin
      writeln(IsOdd(2)); //False. 2 is not an odd number.
      writeln(Not 1);   //Bitwise Complement.

      //if (A and B) then..     //Logical And.
      //if (Not A and B) then.. //Logical Negation.
    End.


    The definition you have as a union is also incorrect. A union is not for "Joining" anything.. A union is for bit-level access. Usually used for accessing the different bits of a value. Using a union directly can also mess you up if you don't take into account "endianness".


    Your union is thus equal to doing:
    Simba Code:
    Function GetRValue(Colour: Integer): Byte;
    Begin
      Result := (Byte)(Colour);
    End;

    Function GetGValue(Colour: Integer): Byte;
    Begin
      Result := (Byte)((Colour) shr 8);
    End;

    Function GetBValue(Colour: Integer): Byte;
    Begin
      Result := (Byte)((Colour) shr 16);
    End;


    var
      Colour: Integer;
    Begin
      Colour := 16777215;
      writeln(GetRValue(Colour));
      writeln(GetGValue(Colour));
      writeln(GetBValue(Colour));
    End.

    The shifting allows you to access different bits of that 32 bit integer.. The union does exactly this.. Allowing you to NOT have to write out all that crap.. So again, a union isn't for magically joining records or classes or anything. It's actually for accessing individual bits and some other things..



    Your loose syntax example should actually be:
    Simba Code:
    {$X+}

    WriteLn('hoi!');

    begin
      var a, i = 0;
      for a := 0 to 2 do
        i := i + a * 2;
      WriteLn(a);
    end;


    I'm not going to rate this tutorial.. You should fix the mistakes though.. Other than that, good job. You probably already knew all this stuff but it's just to make it clear for everyone else..
    Last edited by Brandon; 10-17-2013 at 12:24 AM.
    I am Ggzz..
    Hackintosher

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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