Enslaved
05-24-2013, 09:35 PM
Basic Tutorial/Guide to Lape :P
Examples from nielsie95's Thread Here (http://villavu.com/forum/showthread.php?t=68613)
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 -
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.
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:
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
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
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.
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)
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.
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:
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)
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
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
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
{$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
function Integer.Next: Integer;
begin
Result := Self + 1;
end;
begin
WriteLn(2.Next);
end;
Will be adding to this when i have time.
Examples from nielsie95's Thread Here (http://villavu.com/forum/showthread.php?t=68613)
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 -
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.
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:
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
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
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.
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)
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.
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:
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)
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
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
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
{$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
function Integer.Next: Integer;
begin
Result := Self + 1;
end;
begin
WriteLn(2.Next);
end;
Will be adding to this when i have time.