Recent

Author Topic: TPSScript question  (Read 603 times)

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 65
TPSScript question
« on: November 29, 2024, 01:20:27 am »
Hi, I want to ask a question regarding the use of the script LCL. I am writing a small server app, but I want it to be usable for a couple of different sites. I am using Indy UDP Server for network communications. Different sites may have different messages I need to receive and process but I want to keep to core servercode the same. So my question is, on processing the UDP message (IdUDPServerUDPRead Event) can I inject a script to handle the messages? I thought I would ask before going down the rabbit hole of trying it. Thanks in advance :-)

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 65
Re: TPSScript question
« Reply #1 on: November 29, 2024, 06:19:05 am »
OK so I have been doing lots of reading and maybe the best option is to create me own scripting with a function call to process.

cdbc

  • Hero Member
  • *****
  • Posts: 1656
    • http://www.cdbc.dk
Re: TPSScript question
« Reply #2 on: November 29, 2024, 07:15:41 am »
Hi
Why not, simply create an interface to your data-object(s) and then let the core udp-read code *only* handle the interface to the data-object(s), that way you don't care /how/ the interface is implemented, in the concrete data-object (the interface stays the same)...
I think that should work just fine  :D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

egsuh

  • Hero Member
  • *****
  • Posts: 1490
Re: TPSScript question
« Reply #3 on: November 29, 2024, 07:51:13 am »
I tried to use PascalScripts but have never actually used PascalScript. Based on that small piece of knowledge...

If you have full list of possible messages then interface or using object's virtual methods would be better.

But if other kinds of messages will be added, you may use PascalScript so that variant parts are provided through ini file or in other way, and make your whole application compile and run the pascal script. Then you don't have to recompile other parts. Theoretically.

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 65
Re: TPSScript question
« Reply #4 on: November 29, 2024, 08:57:26 am »
I tried to use PascalScripts but have never actually used PascalScript. Based on that small piece of knowledge...

If you have full list of possible messages then interface or using object's virtual methods would be better.

But if other kinds of messages will be added, you may use PascalScript so that variant parts are provided through ini file or in other way, and make your whole application compile and run the pascal script. Then you don't have to recompile other parts. Theoretically.

The messages maybe added to  or removed. I like the idea of a script but not sure how to implement it.

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 65
Re: TPSScript question
« Reply #5 on: November 29, 2024, 09:04:03 am »
Hi
Why not, simply create an interface to your data-object(s) and then let the core udp-read code *only* handle the interface to the data-object(s), that way you don't care /how/ the interface is implemented, in the concrete data-object (the interface stays the same)...
I think that should work just fine  :D
Regards Benny

So if I understand correctly I take the data received from interface and send that to a function that calls the scripted section ? I need to dig through as many examples of script uses to get an idea how to do this.

I was going to create a text file that holds the messages and and instructions to perform for said message. When UDP-read event is called send that to a function that matches the message then performs the instruction. ( the idea is only in its infancy)

A script would be nice in that I can easily use logic (ie if ..message .. then )

egsuh

  • Hero Member
  • *****
  • Posts: 1490
Re: TPSScript question
« Reply #6 on: November 30, 2024, 06:01:02 am »
Here's a simple example.

https://forum.lazarus.freepascal.org/index.php/topic,68685.msg531356.html#msg531356


The interface Benny said is not user interface, I guess.  Please see:

https://wiki.freepascal.org/Understanding_Interfaces


« Last Edit: November 30, 2024, 06:04:11 am by egsuh »

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 65
Re: TPSScript question
« Reply #7 on: November 30, 2024, 07:23:32 am »
Here's a simple example.

https://forum.lazarus.freepascal.org/index.php/topic,68685.msg531356.html#msg531356


The interface Benny said is not user interface, I guess.  Please see:

https://wiki.freepascal.org/Understanding_Interfaces

Thanks for making that a bit clearer. I have never used interfaces before. (I actually thought he was talking about the UDP communications.. opps)

I think I have a vague idea how to move forward. I started looking at using the Lape script. I will see which works better for my use case.

 

TinyPortal © 2005-2018