I had a silly idea yesterday, and I'm wondering if there's a sci interface to something like eval-string from a vanilla-ish JS environment (details in π§΅ )
still a bunch of kinks to work out, but preliminary looks are good with a lightly modified scittle:
so, Gnome has an 'extension' mechanism in what seems to be a tweaked JS environment - you can write javascript that e.g. allows for adding panel items, tweaking how workspace switching works, etc... but from my initial research, it seems to lack an interactive experience (e.g. I want to get the list of panel items and maybe shuffle their positions around or something)... I immediately thought "JS, interactive, sci?"
perhaps scittle already works, if you're lucky
you might need to mock something like js/window or so
and else it's not difficult to compile your own SCI thing
scittle exposes scittle.core.eval_string
scittle is what I was looking at as well - is there an 'exported function' at all (as opposed to the script blocks from the examples)? I might just need more hammock time to imagine the picture more clearly
oh... lol... borkdude is the borkdude of running clojure on everything π
I'm worried I might start using that expression at work and people will be confused, but it'll be an opportunity to shill
hehe
This might also be fun to play around with: https://github.com/squint-cljs/cherry/blob/main/doc/embed.md
Hi there, I want to eval a string with sci "(js/Promise.resolve 3)", but I canβt figure out how to setup sci to allow only js/Promise and not the whole js namespace
I added docs now: https://github.com/babashka/sci#classes
Sorry I forgot to create the issue (should have done it immediately). Very nice tho, very explicit, thanks
np
(sci/eval-string "(js/Promise.)" {:classes {'js/Promise js/Promise}})
(sci/eval-string "(js/Promise)" {:classes {'js/Promise js/Promise}})
(sci/eval-string "(js/Promise.resolve 3)" {:classes {'js/Promise js/Promise}})
(sci/eval-string "(js/Promise.resolve 3)" {:classes {'js {'Promise js/Promise}}})
(sci/eval-string "(Promise.resolve 3)" {:classes {'Promise js/Promise}})
(sci/eval-string "(my-promise 3)" {:namespaces {'user {'my-promise js/Promise.resolve}}})
(sci/eval-string "(js/Promise.resolve 3)" {:namespaces {'js {'Promise js/Promise}}})
(sci/eval-string "(.resolve js/Promise 3)" {:namespaces {'js {'Promise js/Promise}}})
(sci/eval-string "(js/Promise.resolve 3)" {:namespaces {'js {'Promise js/Promise}}})
(sci/eval-string "(.resolve js/Promise 3)" {:namespaces {'js {'Promise js/Promise}}})
(sci/eval-string "(.resolve js/Promise 3)" {:namespaces {'js {'Promise goog.global.Promise}}})none of them work, but I found one working:
(sci/eval-string "(.resolve js/Promise 3)" {:namespaces {'js {'Promise goog/global.Promise}} :classes {:allow :all}})What I meant was:
{:classes {'js #js {:Promise js/Promise}}}classes needs to be a map of symbol to host specific object, so not a clojure data structure
(sci/eval-string "(js/Promise.resolve 3)" {:classes #js {:js #js {:Promise js/Promise}}})
:repl/exception!
;
; Execution error (Error) at (<cljs repl>:1).
; [object Object] is not ISeqable
Ok but in the readme, {:classes {'js goog/global :allow :all}} it is a clojure map?
oh maybe mix the two
I'm sorry, like this:
cljs.user=> (sci/eval-string "(js/Promise.resolve 1)" {:classes {'js #js {:Promise js/Promise}}})
#object[Promise [object Promise]]so a clojure map of symbol to a host object
(corrected the other message now too)
Thanks! I've spent so much time on this
Is there a place in the documentation where you think this might be added so others would save time in the future?
My feelings is there is no doc about this x)
OK, if you think it's worth it, can you make an issue about the above?
but I would say here https://github.com/babashka/sci#classes
Sure!
Like I could not transpose the JAVA example for js/xxxx
yes, I can see how that is confusing. But globalThis is basically also a JS object with keys of which Promise is one of the keys, so {'js js/globalThis} is the global map
and {'js #js {:Promise js/Promise}} is basically the same but restricted to one key
yes now I see, but I didn't know that js/ was a valid syntax to access a JS Object (the / part)
thanks!
(I'll make the issue but in 2 hours I have to rush some code)
hmm, got an error using it
minimal example
(sci/eval-string "(.then (js/Promise.resolve 1) (fn [x]))" {:classes {'js #js {:Promise js/Promise}}})
:repl/exception!
;
; Execution error (ExceptionInfo) at (<cljs repl>:1).
; Method then on function Promise() { [native code] } not allowed!
it's the same error I got from other tries
Try allow all
This will still only give access to your exposed promise
works, thanks!
You can create an object with a js key and Promise inside of that and then provide that under classes
Or you can expose Promise as a function or non-global