The basis for an xtalk engine [I/we] control

A place to discuss any and all xTalk implementations, not just LC LCC Forks, but HyperCard, SuperCard, MetaCard, Gain Momentum, Oracle MediaTalk, OpenXION, etc.
Forum rules
Please limit any bashing/harping on any commercial interests to a minimum, thanks!
Post Reply
User avatar
richmond62
Posts: 5234
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: The basis for an xtalk engine we control

Post by richmond62 »

(not sure I'm ready for constructive feedback).
That's no problem at all: I can provide you with destructive feedback if you would prefer that. 8-)
https://richmondmathewson.owlstown.net/
User avatar
tperry2x
Posts: 3488
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: The basis for an xtalk engine we control

Post by tperry2x »

richmond62 wrote: Wed Mar 19, 2025 2:46 pm That's no problem at all: I can provide you with destructive feedback if you would prefer that. 8-)
That's kind of what I'm afraid of :D
I don't want to get demoralised.

In all seriousness though, this isn't what I'd call 'alpha' quality yet - let alone beta. There's a lot missing from it, mostly all to do with objects, and until we have save/load support and a tools palette, you'd find it annoying.
The point of posting these updates is twofold I suppose:

1. To show people that, yes - things are moving forward (however slowly)
2. To let people know where I am with adding a particular thing, issues that crop up, and how I've sorted them.

This is going to be free and open-source for anyone to use without paying anything (as I promised), but I've got some thoughts on that. The documentation I'm writing to go along with this (kind of like the internal dev notes we are missing from LCC), that outlines a custom license agreement on the last page.
User avatar
richmond62
Posts: 5234
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: The basis for an xtalk engine we control

Post by richmond62 »

Well that PDF certainly:

1. Made interesting reading (admittedly probably only for the already converted).

2. Whetted my appetite.

3. I almost had a 'brown sofa moment'. :lol:
-
bSofa.png
bSofa.png (49.68 KiB) Viewed 9570 times
https://richmondmathewson.owlstown.net/
User avatar
tperry2x
Posts: 3488
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: The basis for an xtalk engine we control

Post by tperry2x »

Actually, there's something (seemingly insignificant) but it's on my to-do list.
That's to implement the:

Code: Select all

beep
command, or

Code: Select all

beep [number]
Because there's no method of actually forcing a computer to play it's default alert beep (well, there is on linux - but this has to work for all 4: haiku included ;) ). So, my idea is to choose one of these quick examples I put together:
system-beep.zip
(2.29 KiB) Downloaded 86 times
User avatar
richmond62
Posts: 5234
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: The basis for an xtalk engine we control

Post by richmond62 »

kisspng-wile-e-coyote-and-the-road-runner-marvin-the-mart-tribun-dergi-heretocreate-on-twitter-amp-quot-g-5b6d6342411c85.3785112515338954902667.png
kisspng-wile-e-coyote-and-the-road-runner-marvin-the-mart-tribun-dergi-heretocreate-on-twitter-amp-quot-g-5b6d6342411c85.3785112515338954902667.png (126.42 KiB) Viewed 9527 times
-
https://soundfxcenter.com/download-soun ... nd-effect/
https://richmondmathewson.owlstown.net/
User avatar
tperry2x
Posts: 3488
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: The basis for an xtalk engine we control

Post by tperry2x »

While that would be fun, I think I'd run into legal issues using that :D
User avatar
OpenXTalkPaul
Posts: 2798
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: The basis for an xtalk engine we control

Post by OpenXTalkPaul »

Slightly revised 'open file' still not ready for use, changing command to 'load file' due to the way 'files' are handled in JS within browser context (sandboxed):

Code: Select all

              // Handle load file command
               if (script.startsWith('load ')) {
                   const expr = script.substring(5);
                   if (expr.startsWith('file'))
                     {
                       const theParam = expr.substring(5);
                       let element = document.getElementById('inputData');
                       if (element) {
                            console.log('File Input element does already exist!');

                            let result = inputData.click();
                            // Element exists, proceed with operations
                            let fileInput = document.getElementById('inputData').files[0];
                            console.log(fileInput);
                            fileInput = document.getElementById('inputData').files[0];

                        } else {
                             console.log('File Input element does not exist, creating it...');
                           //  <input type="file" id="inputData" name="fileInput" accept="text/*">
                             const oxtInputFileDiv = document.createElement('div');
                              oxtInputFileDiv.setAttribute('style','display:none');
                              const inFileForm = document.createElement('form');
                              const inFileInput = document.createElement('input');
                              inFileInput.setAttribute('id','inputData');
                              inFileInput.setAttribute('type','file');
                              inFileInput.setAttribute('accept','text/*');
                              inFileForm.appendChild(inFileInput);
                              oxtInputFileDiv.appendChild(inFileForm);
                              document.body.appendChild(oxtInputFileDiv);
                              let result = inputData.click();
                              let fileInput = document.getElementById('inputData').files[0];
                              //const fileInput = document.getElementById('inputData');
                              // console.log( fileInput.files[0] );
                          }
                          let fileInput = document.getElementById('inputData').files[0];
                          console.log( fileInput );
                          // Read the file
                          let reader = new FileReader(fileInput);
                          reader.onloadend = () => {
                            this.it = reader.result;
                            console.log(reader.result);
                            // return this.it;
                          };
                          reader.onerror = () => {
                            showMessage("Error reading the file. Please try again.", "error");
                          };
                         let tResult = reader.readAsText( fileInput );
                         // const tResult = reader.readAsText( theFile,'UTF-8');
                         this.it = reader.result;

                     }
                     return this.it;
               }
use:

Code: Select all

load file
wait 1 -- give it a little time to load the file data
put it
currently does what 'answer file' does, sort-of, you only get back the file name, not the file path. That is due to the way web browsers work with sandboxing.

Also it would help to have that invisible file input form element was in the index.html Currently it fails to load a file only the first time it is called as it checks for the element and creates it if it doesn't already exist in the html, once the element exists it works. I think maybe 'await / promise' is probably in order for the former.
User avatar
tperry2x
Posts: 3488
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: The basis for an xtalk engine we control

Post by tperry2x »

Thanks Paul. That's a good point. So does using "load file" instead get around the browser CORS errors, or do you still have to modify headers and stuff to get that to work?

In theory, lets assume I was just loading and saving from a stacks subdirectory, would that work? We could even symlink / alias that 'stacks' folder in the wrapper to point to the user's documents folder in something called 'webstacks'?
Kdjanz
Posts: 40
Joined: Mon Sep 13, 2021 5:02 am
Contact:

Re: The basis for an xtalk engine we control

Post by Kdjanz »

I did extensive testing as I was trying to confuse it, but seems to pass all these tests:
This is essential if you want to localize your stacks into another language. The buttons and fields may change names but the ID will always be the same and work the same not matter what.
User avatar
OpenXTalkPaul
Posts: 2798
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: The basis for an xtalk engine we control

Post by OpenXTalkPaul »

tperry2x wrote: Wed Mar 19, 2025 8:00 pm Thanks Paul. That's a good point. So does using "load file" instead get around the browser CORS errors, or do you still have to modify headers and stuff to get that to work?

In theory, lets assume I was just loading and saving from a stacks subdirectory, would that work? We could even symlink / alias that 'stacks' folder in the wrapper to point to the user's documents folder in something called 'webstacks'?
See this is where something like an Electron web app-to-desktop app wrapper is needed. Electron has it's own file reading 'fs' (FileSystem) API that can be used which provides more traditional desktop app style file system access, like listing directories and like incremental reads writes to disks. The web file reader APIs doesn't do that stuff for security reasons. You get back file reference objects which have properties filled in with details about the file, but it's not a file, the API uses it to read in it's bytes from disk into memory before you can access any data from the file that it points to. It is a bit like a symbolic link I guess, or maybe a bit more like a File reference object seen in some other programming languages such as Objective C. The underlying disk I/O methods are opaque, abstracted away from calling code. What you get back with the file input method here is a FileList-array of File objects (https://developer.mozilla.org/en-US/docs/Web/API/File) which have details like name, byte size, MIME type, so then you pass these file-objects to the file reader to slurp up some data from the BLOB, it may be media such as an image format, and one can have it returned as the raw binary data, or text, or base64 encoded into a DataURL string for doing things with it.
Google AI summary:
Binary Large Object. It represents raw, immutable, file-like data. Blobs can contain various types of data, including text, images, audio, and video. They are often used for handling large files and data streams in web applications.
Here's an overview of the FileReader API: https://developer.mozilla.org/en-US/doc ... FileReader

I don't think that CORS, Cross-Origin Resource Sharing comes into play here, the script is running local and doing a user initiated loading of a local file, so there's no origin being crossed, in fact the way I'm running this there's no servers involved at all.
But yeah for CORS, like loading an additional JS library from a remote CDN, you would need to use XHTTPRequest (https://developer.mozilla.org/en-US/doc ... ttpRequest) and probably set a header thing too. I prefer keeping everything for a project together in one place, or even in one file if possible, preferably local (no clouds), so I've never used that.
league_of_gents.png
league_of_gents.png (463.03 KiB) Viewed 8725 times
User avatar
OpenXTalkPaul
Posts: 2798
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: The basis for an xtalk engine we control

Post by OpenXTalkPaul »

In this screen shot you can see the structure of the file object, and it's file and blob prototypes ( 'file' inherits from 'blob' properties too):
Screen Shot 2025-03-20 at 12.13.26 AM.png
Screen Shot 2025-03-20 at 12.13.26 AM.png (129.3 KiB) Viewed 8206 times
There's no relative path property data in there (this is running in Safari), but could always use the URL of the index.html document itself and derive a folder path from that for offline local disk or shell scripting stuff.
User avatar
OpenXTalkPaul
Posts: 2798
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: The basis for an xtalk engine we control

Post by OpenXTalkPaul »

I updated the ''load file' code in the previous post, it's actually reading text from a file ref object and putiing it into the it variable, but it still has async related problems loading the file and the files data. Web JavaScript now days is asynchronous as a default, but there needs to be some blocking while the input form updates and while the FileReader reads the data from the file object.

I put the form/input element into the index.html but that didn't help, the first time 'load file' is issued it tries to read the file in before the file reference object is created and so it errors due to the 'undefined' / null value in the fileInput, the second time a 'load file' command is issued it loads the data into 'it' as expected if you give it a little time to load the data first. The third time and thereafter it works right away.
Screen Shot 2025-03-20 at 11.29.52 AM.png
Screen Shot 2025-03-20 at 11.29.52 AM.png (54.13 KiB) Viewed 7549 times
dandandandan
Posts: 16
Joined: Thu May 05, 2022 9:02 pm
Contact:

Re: The basis for an xtalk engine we control

Post by dandandandan »

Is the current code available?
User avatar
OpenXTalkPaul
Posts: 2798
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: The basis for an xtalk engine we control

Post by OpenXTalkPaul »

dandandandan wrote: Thu Mar 20, 2025 5:50 pm Is the current code available?
The code for 'load file' is in a few posts back:
https://openxtalk.org/forum/viewtopic.p ... 197#p14197

The code for the interpreter is currently being shared by Tom on a shared mega account that I created to use for collaboration since some people are really not keen on using GitHub. Personally I think it would be better to use GitHub or similar version control system, out in the open / open-source, but I'm flexible.
User avatar
OpenXTalkPaul
Posts: 2798
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: The basis for an xtalk engine we control

Post by OpenXTalkPaul »

baseConvert(28,10,16) --1c, dec>hex
I didn't make a multi-base baseConvert equivalent
but I did make a function hex( )

Code: Select all

        // Handle hex function
        const hexMatch = expr.match(/^hex\s*\(\s*(.+?)\s*\)$/i);
        if (hexMatch) {
            const [_, number] = hexMatch;
            const numberValue = this.evaluateExpression(number);
            const value = Number(numberValue);
            if (isNaN(value)) {
                throw new Error('hex: argument must be a number');
            }
            return value.toString(16);
        }
Use from script like:

Code: Select all

put hex(28) -- 1c
put hex(127) -- 7f
put hex(4294967295) -- ffffffff max value for a 32bit unsigned integer
put hex(18446744073709551615) -- ffffffffffffffff can't handle max value for a 64bit unsigned integer, fails
Trying to stress test it with that last one, it returned 10000000000000000 when it should have return ffffffffffffffff
So I'm guessing the JS number.toString(base) method can't handle 64bit integers?

I have an old xTalk script that takes a different math approach to converting decimal to hex-string that I think could handle arbitrarily large numbers, IIRC I based it on a really ancient (1980s) script that does the same but for decimal to binary. But that's xTalk, and we're doing a xTalk<>JS interpreter.

I was thinking number base could like a property, so instead of calling a function hex()
it could be an expression 'the hex of 28 and the reverse: 'the dec of 1c'

Here's a quick (no checking for valid hex chars) dec() function to go with hex():

Code: Select all

      // Handle dec function
        const decMatch = expr.match(/^dec\s*\(\s*(.+?)\s*\)$/i);
        if (decMatch) {
            const [_, thehex] = decMatch;
            return parseInt( thehex, 16);
        }
test:

Code: Select all

put dec(1c) -- 28 pass
put hex(18446744073709551615) -- 10000000000000000, should be ffffffffffffffff -- fail
put dec(ffffffffffffffff) -- 18446744073709552000, should be 18446744073709551615 -- fail
put hex(18446744073709552000) -- 10000000000000000
So it seems that the maximum value these two JS methods can accurately handle (at least without scientific notation) is 18,446,744,073,709,551,615 ?

Anyway it's not quite a true stand-in for baseConvert (https://livecode.fandom.com/wiki/BaseConvert ) which can handle conversions to other number base besides hex and binary.
User avatar
tperry2x
Posts: 3488
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: The basis for an xtalk engine we control

Post by tperry2x »

I seriously have a massive headache (no joke). However, I've also been making progress.
(boring update coming shortly).
User avatar
tperry2x
Posts: 3488
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: The basis for an xtalk engine we control

Post by tperry2x »

Version 114
Added the ceiling (and ceil synonym) function, as in this example:

Code: Select all

put ceiling(33.25) into tResult -- outputs 34
put ceil(12.9) into tResult -- outputs 13
If I try and trip it up:

Code: Select all

put ceiling("abc")
returns:

Code: Select all

Error: ceiling: argument must be a number
(as you'd expect)
User avatar
tperry2x
Posts: 3488
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: The basis for an xtalk engine we control

Post by tperry2x »

Version 115
More tweaks to the script editor (I needed a rest from adding math(s) functions).

Now, if I put this in a button:
script-editor-working.png
script-editor-working.png (28.66 KiB) Viewed 5919 times
It's actually formatted correctly with the correct colours, it knows how to handle strings and comments properly too.
User avatar
tperry2x
Posts: 3488
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: The basis for an xtalk engine we control

Post by tperry2x »

Here's why I have a massive headache!

Version 116
Added the beep command. You can now use:

Code: Select all

beep -- play an audible beep once
beep 4 -- beeps 4 times
Added floor math function.

Code: Select all

put floor(33.25) -- outputs 33
put floor(12.9) -- outputs 12
put floor(-3.7) -- outputs -4
Added geometric mean function.

Code: Select all

put geometricMean(10,20,25) -- outputs 17.1
put geometricMean(4,9) -- outputs 6
Added harmonic mean function.

Code: Select all

put harmonicMean(10,20,25) -- outputs 15.79
put harmonicMean(4,9) -- outputs 5.54
Added median function

Code: Select all

put median(10,20,30) -- outputs 20
put median(10,20,30,40) -- outputs 25
put median(5,1,3,2,4) -- outputs 3
Added max function

Code: Select all

put max(10,20,30) -- outputs 30
put max(42,17,29) -- outputs 42
put max(-5,-10,-3) -- outputs -3
added min function

Code: Select all

put min(10,20,30) -- outputs 10
put min(42,17,29) -- outputs 17
put min(-5,-10,-3) -- outputs -10
Added round and statround functions

Code: Select all

put round(12.5) -- outputs 13
put round(12.4) -- outputs 12
put round(-3.7) -- outputs -4
put statRound(10.5) -- outputs 10
put statRound(11.5) -- outputs 12
User avatar
tperry2x
Posts: 3488
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: The basis for an xtalk engine we control

Post by tperry2x »

Version 117
Added a new section to the top of each testing page.
This now tracks the number of tests that are failed, passed, and skipped.
If any tests fail, it'll put these at the top of each testing page (sorted alphabetically).
This is useful when adding/testing new functions.
test-summary.png
test-summary.png (20.97 KiB) Viewed 5918 times
I also added a "testing3.html" page, so that can be used as a blank template in future if we want more test pages.
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests