Feature Support for scripting in JavaScript

ikzann

Member
Oh, and I am quite sure I used svn add before generating the latest couple of patch files. If something is still not applying cleanly, please let me know.
 

fronobulax

Developer
Staff member
Thanks, frono, and thanks for all the review you've done so far. Here's a patch that has rhino in a src/jar/ directory (placing the jar still needs to be done manually). Can split this up into a sequence of patches if you'd like, but i suspect it would be easier for someone with commit access to do so when we are actually ready to commit.

v6 had some bad sections or whatever it is called when a patch doesn't work. I did src/jar and rhino manually. It built but running generated lots of errors. I'm thinking the errors are in the patch are the cause but bottom line is the patch didn't completely apply.
 

ikzann

Member
Hm, it applied cleanly for me, but on double check there were some issues with the build.xml changes. Here's an updated patch. I executed the following commands to apply it. Please let me know if this does not work for you.
Bash:
svn checkout https://svn.code.sf.net/p/kolmafia/code/ kolmafia-code
cd kolmafia-code
svn patch ~/Documents/Projects/kol/old-kolmafia/javascript-v7.txt
mkdir -p src/jar
cp ~/Downloads/rhino-1.7.13.jar src/jar/
ant daily
java -jar dist/KoLmafia-20501M.jar --CLI
# js Item.get("hair spray")
 

Attachments

  • javascript-v7.txt
    425.1 KB · Views: 3

fronobulax

Developer
Staff member
v7 worked.

I'm not understanding why reverting it was a multi-step process but I'm getting impatient so...

I get in trouble assuming silence is consensus but in the absence of other opinions, I am inclined to implement src/jar and the associated build changes, commit them, add the rhino jar and commit it and then commit v7. Maybe I'll do it 11/19 in the morning EST?

I note pizzable.js in the script most recently used list. Probably worth some thought at a later time about handling extensions. test, test.ash and test.js could be three different files and we should protect a user who is foolish enough to have them, as much as possible.
 

MCroft

Developer
Staff member
might be nice (but not show stopping, in any way) to add some of those js Item.get("hair spray") items to the tests that ant test runs.
 

fronobulax

Developer
Staff member
might be nice (but not show stopping, in any way) to add some of those js Item.get("hair spray") items to the tests that ant test runs.
We can certainly think about it but the test / JUnit environment for mafia is enough different from the one I have forgotten how to use that I'm not sure I want to reclimb the learning curve. Although there is one example of using a script in a test so...
 

MCroft

Developer
Staff member
"More tests" is on my wish-list of things for the app, even though I didn't do it for my last change.
 

fronobulax

Developer
Staff member
The fear of two threads confusing things was founded.


In the interest of moving ahead, lets accept the src/jar convention. I'll create the directories and check in rhino. I'm OK with the build.xml changes in the Javascript patch so I will extract them and check them in separately from the rest of the JavaScript.

The daily task made the same jar with the directory and rhino present as it did without, using the changed build so breaking things apart doesn't seem to hurt anything or even make a difference until Javascript is added.

I intend to check in both the build changes and the JavaScript changes as they exist later today, trusting that with three sets of eyeballs it is a matter of asking forgiveness, not permission :)
 

gausie

D̰͕̝͚̤̥̙̐̇̑͗̒e͍͔͎͈͔ͥ̉̔̅́̈l̠̪̜͓̲ͧ̍̈́͛v̻̾ͤe͗̃ͥ̐̊ͬp̔͒ͪ
Staff member
I have been running the latest patch and not encountering any issues at all while actually writing and running JS.

I've also been tinkering with a widely-featured library I would like to publish for mafia JS script-authors to use 👀
 

fronobulax

Developer
Staff member
r20505

It built in Jenkins so I think we can shift to bug reporting and new features, both of which might deserve their own thread.

I confess I have not verified the source for adherence to formatting standards and may never do so.

I did not update .classpath since I don't need the file and there seemed to be an end of line issue.
 

Jamesernator

New member
This is pretty cool to see, I've actually started recently on creating a lighter mafia-esque system that can be loaded into KoL directly via chat commands. My intention with it is to provide a mafia-lite experience that works anywhere, in particular mobile. The fact that KoLMafia will support JS scripts is cool because it means I can simply run them with a mock.

There's only one thing I'm wary of though and that's the fact all the ash functions are (presumably) synchronous. This behaviour is a lot harder to mock as a lot of things in the browser are inherently asynchronous*. While this is not a total killer, it does make it a lot more complex as it requires synchronizing everything through a SharedArrayBuffer with Atomics.wait. The problem with this is that (at least for now) it completely kills the ability to use it on any browser other than desktop Chrome, as no other browser supports SharedArrayBuffer/Atomics.wait (Firefox does under certain conditions, but KoL does not send the appropriate headers to enable it).

* As an example navigating the main iframe requires using `mainPane.addEventListener("load", () => ...)` which is strictly asynchronous. There is no way to make this (amongst many other things) in the browser synchronous.
 
Top