Coder Social home page Coder Social logo

lape's Introduction

Lape

tests

Lape is a scripting engine with a Pascal derived syntax for Free Pascal and Delphi. It's written with speed and a broad platform compatibility in mind. The syntax is backwards compatible with Pascal Script (to a certain degree).

Lape is:

  • A scripting engine
  • A Pascal derived language
    • Basetypes: Integer, Float, Char, String, Boolean, Variant, Array, Record, Union, Enum, Set, Pointer, Function pointer
    • Operations: := = <> > >= < <= @ ^ + - * / ** AND OR DIV XOR NOT IN SHL SHR MOD
    • Constructs: If For Case Repeat While Try Label
    • Optional C style operators: += /= *= -=
    • Internal and external functions (with support for default params & type methods)
    • Internal/external variables and constants (every variable is represented exactly as how it would be by FPC/Delphi)
    • Function directives: override, overload, static, deprecated, experimental, unimplemented
    • Support for local (nested) declarations. So function can have their own constants/types/variables/functions.
    • Operator overloading
    • Multiline strings using double quotes "
    • Optional array "helpers" such as array.SetLength(5), array.Pop() and many more
  • Portable
    • Fully written in FPC/Delphi. No need for external libraries.
    • Tested with Linux(x64/aarch64), Windows(x86/x64) and Mac OS(x64/aarch64), but supports virtually every platform FPC supports.
  • Extensible
    • New types can easily be added with specified behaviour for operations.
    • Optional foreign function interface which allows native calling of Lape functions and importing of functions without creating wrappers.
  • Fast

Simple example of running a script:

  • Remember to add unit & include search paths to the lape directory
uses
  Classes, Sysutils, lpparser, lpcompiler, lpinterpreter;   

const
  MyScript = 'function DiceRoll: Int32;'           + LineEnding +
             'begin'                               + LineEnding +
             '  Result := Random(1, 6);'           + LineEnding +
             'end;'                                + LineEnding +
             ''                                    + LineEnding +
             'begin'                               + LineEnding +
             '  WriteLn("Rolled a ", DiceRoll());' + LineEnding +
             'end.';

var
  Compiler: TLapeCompiler;
begin
  Randomize();

  Compiler := TLapeCompiler.Create(TLapeTokenizerString.Create(MyScript));
  try
    if Compiler.Compile() then
      RunCode(Compiler.Emitter);
  except
    on E: Exception do
      WriteLn(E.ToString());
  end;
  Compiler.Free();

  ReadLn;
end.

lape's People

Contributors

nielsad avatar ollydev avatar slackydev avatar merlijnwajer avatar ineedbots avatar johnpeel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.