Recent

Author Topic: Who uses embedded languages in their Lazarus projects and what for?  (Read 682 times)

vfclists

  • Hero Member
  • *****
  • Posts: 1109
    • HowTos Considered Harmful?
Who uses embedded languages in their Lazarus projects and what for?

I'm talking about languages like Lua, Scheme, Lisp etc?

Are they used to provide functionality for the main Lazarus program, or is more for the FPC and Lazarus to support the functionality which is primarily implemented in the embedded language?

vclua for instance uses the LCL to provide a GUI for functionality implemented in Lua.
Lazarus 3.0/FPC 3.2.2

MarkMLl

  • Hero Member
  • *****
  • Posts: 7681
Re: Who uses embedded languages in their Lazarus projects and what for?
« Reply #1 on: September 15, 2024, 11:18:12 am »
I don't know whether this will count, but for the last 25 years or so I've had my own scripting language (implemented using Meta-2) embedded in multiple programs to either collect data via (originally) a modem, to present it to the user (e.g. as something spreadsheet-like) or to reformat the presented information into something that a client can handle easily (e.g. a spreadsheet into absolutely minimal HTML). The scripts themselves are typically fetched from database tables.

The advantage is that... well, apart from anything else when I started off nothing similar was available, so I waded in using tools with which I was familiar from the 1980s.

Besides that, it is simple to embed a concept like rotating the representation of data using complex embedded SQL (and FPC /still/ doesn't allow SQL to be embedded where it's needed), or to encapsulate complex error conditions after the failure of a data transfer, using different quoting conventions to distinguish string types (e.g. literal vs regex), adding syntax and operators missing from Pascal (e.g. ?? as a C-style conditional, <| |> as rotation operators), vastly improved error reporting... and so on.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

AlexTP

  • Hero Member
  • *****
  • Posts: 2465
    • UVviewsoft
Re: Who uses embedded languages in their Lazarus projects and what for?
« Reply #2 on: September 15, 2024, 01:18:59 pm »
You maybe already know about Python component.
I recommend it.
https://wiki.freepascal.org/Using_Python_in_Lazarus_on_Windows/Linux

alpine

  • Hero Member
  • *****
  • Posts: 1263
Re: Who uses embedded languages in their Lazarus projects and what for?
« Reply #3 on: September 15, 2024, 01:23:32 pm »
Who uses embedded languages in their Lazarus projects and what for?
I'm using Lua to control some digital signage attached to. It is simpler to edit a few lines of Lua code in situ than to recompile the whole project.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

MarkMLl

  • Hero Member
  • *****
  • Posts: 7681
Re: Who uses embedded languages in their Lazarus projects and what for?
« Reply #4 on: September 15, 2024, 02:03:42 pm »
You maybe already know about Python component.
I recommend it.
https://wiki.freepascal.org/Using_Python_in_Lazarus_on_Windows/Linux

And what year did that become available? Also I've done extensive work on a binding- mainly v2- with a view to having it wither statically or dynamically linkable.

So the answer has to be... yes, I do :-)

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Thaddy

  • Hero Member
  • *****
  • Posts: 15717
  • Censorship about opinions does not belong here.
Re: Who uses embedded languages in their Lazarus projects and what for?
« Reply #5 on: September 15, 2024, 02:26:43 pm »
Python4lazarus is already quite old and stable.

That said:
I use embedded languages for runtime evaluation or even design by the end user.
- Python
- Ecmascript (vbscript, jscript)
- lua
- Pascalscript.

If it is for myself it is usually Python or maybe Pascalscript.
« Last Edit: September 15, 2024, 02:30:32 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Warfley

  • Hero Member
  • *****
  • Posts: 1600
Re: Who uses embedded languages in their Lazarus projects and what for?
« Reply #6 on: September 15, 2024, 02:56:06 pm »
About a year ago, I was reverse engineering the file format of an old game, which consisted of records of fixed size where I needed to figure out which field in the record had which purpose. And while staring at the records would allow me to guess these things, to verify the assumptions I needed to have some structured approach to check in all the records.

So for this I created a small query language with Gold (and some tooling and engines to work with gold), which allowed me to write small queries. For example I suspected that the very first field is an ID field for the block and that every block Id is continiously incremented, so I verified this by running this query:
Code: Pascal  [Select][+][-]
  1. mapRecords[currentID].IntField1 = mapRecords[currentID - 1].IntField1 + 1
Which my engine would parse, and then go through each record and execute with the currentID of the record

And while I never finished that project because life got in my way, this simple query language already worked quite well, and it's quite easy to embed something like this using Gold
« Last Edit: September 15, 2024, 02:58:08 pm by Warfley »

MarkMLl

  • Hero Member
  • *****
  • Posts: 7681
Re: Who uses embedded languages in their Lazarus projects and what for?
« Reply #7 on: September 15, 2024, 04:01:39 pm »
So for this I created a small query language with Gold (and some tooling

I've thought about using that approach to work with arbitrary serial comms protocols (and those without experience in the field don't appreciate just how many there were), particularly after dimly-remembered experience with Burroughs Network Definition Language which underpinned much of their datacomms. However when I went back to a manual on Bitsavers it turned out that the configurability was far less than I recalled: very basic settings for address size, CRC type etc. but basically it was just tweaking the settings of a hardcoded protocol manager. So compared with Life, that lost out badly :-)

One thing I have done however: since Meta-2 (which I mentioned earlier) is built on top of a number of basic lexemes I was able to add "comment" to those with specific semantics, and that was enough to allow me to subsequently parse XML etc. to good effect. In fact one area where that turned out to be useful was parsing SNMP MIB files, which allowed me to get some way towards automatically building a class to represent a specific type of router etc. (inspired by some abandonware from IIRC Compaq).

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

LV

  • Jr. Member
  • **
  • Posts: 75
Re: Who uses embedded languages in their Lazarus projects and what for?
« Reply #8 on: September 15, 2024, 04:38:21 pm »
In the last year or so, I've been using PascalScript in some of my projects. It's included in the Lazarus installer, and it works great on both Windows and Linux. It adds some cool features to your apps at runtime.

Updated: So, for instance, in one project, the end user of a running app can write scripts to read and write data, do analysis with linear algebra and math stats, create charts, and so on. The interface's built using Lazarus.
« Last Edit: September 15, 2024, 04:58:00 pm by LV »

vfclists

  • Hero Member
  • *****
  • Posts: 1109
    • HowTos Considered Harmful?
Re: Who uses embedded languages in their Lazarus projects and what for?
« Reply #9 on: September 15, 2024, 05:12:21 pm »
In the last year or so, I've been using PascalScript in some of my projects. It's included in the Lazarus installer, and it works great on both Windows and Linux. It adds some cool features to your apps at runtime.

Updated: So, for instance, in one project, the end user of a running app can write scripts to read and write data, do analysis with linear algebra and math stats, create charts, and so on. The interface's built using Lazarus.

What steps do you have to take to ensure your scripts don't crash the program?

Is it hard or impossible for your Pascal scripts to crash the program?
Lazarus 3.0/FPC 3.2.2

LV

  • Jr. Member
  • **
  • Posts: 75
Re: Who uses embedded languages in their Lazarus projects and what for?
« Reply #10 on: September 15, 2024, 05:52:44 pm »
Quote
What steps do you have to take to ensure your scripts don't crash the program?

Is it hard or impossible for your Pascal scripts to crash the program?

The question is pretty general. You just need to follow the same steps you would take when programming in Free Pascal with Lazarus. In my experience, it's been pretty easy. I mean, I had a script that crashed, but not the app. But after fixing the script errors, everything kept working.
« Last Edit: September 15, 2024, 05:56:34 pm by LV »

gidesa

  • Full Member
  • ***
  • Posts: 116
Re: Who uses embedded languages in their Lazarus projects and what for?
« Reply #11 on: September 15, 2024, 06:03:39 pm »
Hello,
I have used the embedded Javascript engine Duktape (https://duktape.org/).
It's natively designed to be embedded, with a stack-based approach to pass data from/to
the interpreter.
The engine is entirely contained in a tiny Dll of less than 200 kb.
I used it in a framework to test web programs. The tests are written in the scripting language.
Lua is also a very good scripting engine, designed to be easily embedded.

 

TinyPortal © 2005-2018