~technomancy/fennel

4 2

Re: Fennel -> Hammerspoon repl

Details
Message ID
<87lfr4thzg.fsf@hagelb.org>
DKIM signature
missing
Download raw message
Ag Ibragimov <agzam.ibragimov@gmail.com> writes:

> Right now my struggle is - I need to be able to use JeeJah as a
> library. So I started with something like this:
>
> #+begin_src fennel
> (local co (require :coroutine))
> (local jeejah (require :jeejah))
> (global jco (jeejah.start 3444 {:debug true :fennel true}))
> #+end_src

> (hs.hotkey.bind [:cmd] :t nil (fn [] (co.resume jco)))

OK, so one problem here is that the Fennel support in Jeejah is
currently only implemented for the shell launcher. My bad; I had
forgotten about that detail. Right now Jeejah as a library knows nothing
about Fennel; you would need to copy the middleware from the bin script
into your invocation:

    https://gitlab.com/technomancy/jeejah/blob/master/bin/jeejah#L15

Other than that it looks pretty sensible for testing purposes; once you
get it working you can look into how to tie it into the event loop so it
doesn't need manual intervention.

> And the code worked from within Hammerspoon context. I was able to
> connect using Monroe, but I couldn't figure out how for example to
> print something like "Yo! It works" every time I eval stuff in the
> REPL (*monroe* buffer)

If you want to be able to react every time any message is received, you
would need to make your middleware do that.

> I also saw somewhere ~(jeejah.broadcast)~ and have no idea how that works.

You could use broadcast to send output from the server to all connected
repl clients by sending a message with an "out" field showing the output
you want to send, but I haven't really tried this. It's probably not
that useful unless you have custom ops.

The problem with locals is that we use `fennel.eval' directly instead of
tying it into `fennel.repl' which is where the locals-saving
implementation we have lives. But probably it would be better to
reimplement locals-saving within Jeejah so it would work with Fennel
*or* Lua.

-Phil

Re: Fennel -> Hammerspoon repl

Ag Ibragimov
Details
Message ID
<m1k16nhpw1.fsf@gmail.com>
In-Reply-To
<87lfr4thzg.fsf@hagelb.org> (view parent)
DKIM signature
missing
Download raw message
Okay, I tried this:

#+begin_src fennel
    (local co (require :coroutine))
    (local jeejah (require :jeejah))
    (local
     jco
     (jeejah.start
      3444
      {
       :debug true
       :sandbox {}
       :middleware (fn [f msg]
                     (print "something happening")
                     (f msg))}))

  (hs.hotkey.bind
   [:ctrl :cmd] :t nil
   (fn [] (co.resume jco)))
#+end_src


Connected with Monroe, resumed coroutine, because debug is enabled it printed 'Connected' in the console. But I don't think it's getting into the middleware function at all. I tried typing in the REPL and then resumed coroutine multiple times, nothing is happening.

On Sun 22 Dec 2019 at 08:58, Phil Hagelberg <phil@hagelb.org> wrote:

> Ag Ibragimov <agzam.ibragimov@gmail.com> writes:
>
>> Right now my struggle is - I need to be able to use JeeJah as a
>> library. So I started with something like this:
>>
>> #+begin_src fennel
>> (local co (require :coroutine))
>> (local jeejah (require :jeejah))
>> (global jco (jeejah.start 3444 {:debug true :fennel true}))
>> #+end_src
>
>> (hs.hotkey.bind [:cmd] :t nil (fn [] (co.resume jco)))
>
> OK, so one problem here is that the Fennel support in Jeejah is
> currently only implemented for the shell launcher. My bad; I had
> forgotten about that detail. Right now Jeejah as a library knows nothing
> about Fennel; you would need to copy the middleware from the bin script
> into your invocation:
>
>     https://gitlab.com/technomancy/jeejah/blob/master/bin/jeejah#L15
>
> Other than that it looks pretty sensible for testing purposes; once you
> get it working you can look into how to tie it into the event loop so it
> doesn't need manual intervention.
>
>> And the code worked from within Hammerspoon context. I was able to
>> connect using Monroe, but I couldn't figure out how for example to
>> print something like "Yo! It works" every time I eval stuff in the
>> REPL (*monroe* buffer)
>
> If you want to be able to react every time any message is received, you
> would need to make your middleware do that.
>
>> I also saw somewhere ~(jeejah.broadcast)~ and have no idea how that works.
>
> You could use broadcast to send output from the server to all connected
> repl clients by sending a message with an "out" field showing the output
> you want to send, but I haven't really tried this. It's probably not
> that useful unless you have custom ops.
>
> The problem with locals is that we use `fennel.eval' directly instead of
> tying it into `fennel.repl' which is where the locals-saving
> implementation we have lives. But probably it would be better to
> reimplement locals-saving within Jeejah so it would work with Fennel
> *or* Lua.
>
> -Phil

Re: Fennel -> Hammerspoon repl

Details
Message ID
<87h81qu611.fsf@hagelb.org>
In-Reply-To
<m1k16nhpw1.fsf@gmail.com> (view parent)
DKIM signature
missing
Download raw message
Ag Ibragimov <agzam.ibragimov@gmail.com> writes:

> Okay, I tried this:
>
> [...]
>
> Connected with Monroe, resumed coroutine, because debug is enabled it
> printed 'Connected' in the console. But I don't think it's getting
> into the middleware function at all. I tried typing in the REPL and
> then resumed coroutine multiple times, nothing is happening.

I pushed a change to Jeejah to move Fennel handling from being a
middleware to being a custom op, so it's easier to invoke when using
Jeejah as a library. (This also means you get access to locals-saving
functionality from the standard Fennel repl.)

I don't have a way to run Hammerspoon, but this works for me as a
standalone script:

    (local jeejah (require :jeejah))
    (local jco (jeejah.start 3444
                             {:debug true
                              :fennel true
                              :middleware (fn [f msg]
                                            (print "something happening")
                                            (f msg))}))

    (coroutine.resume jco)

    (while true
      (io.read)
      (coroutine.resume jco)
      (coroutine.resume jco))

The while loop at the end is to simulate requiring input to resume the
coroutine. Note that the `coroutine` module is loaded by default, so
it's not necessary to require it. Two resumes are required because
both the outer server receive loop and the inner connection-level
coroutine need to run.

Hope that helps.

-Phil

Re: Fennel -> Hammerspoon repl

Ag Ibragimov
Details
Message ID
<m1h81nhi29.fsf@gmail.com>
In-Reply-To
<87h81qu611.fsf@hagelb.org> (view parent)
DKIM signature
missing
Download raw message
I tried this way and it didn't work for me. I am clearly missing something here.

- I have cloned jeejah repo and did ~luarocks make ./jeejah-0.3.0-1.rockspec~;
- I used the snippet, executing it from lua context, not Hammerspoon,
- and the snippet with :fennel option didn't work, it now throws:

    /usr/local/bin/lua: /usr/local/share/lua/5.3/jeejah.lua:324: module 'jeejah.fenneleval' not found:
      no field package.preload['jeejah.fenneleval']
      no file '/usr/local/share/lua/5.3/jeejah/fenneleval.lua'
      no file '/usr/local/share/lua/5.3/jeejah/fenneleval/init.lua'
      no file '/usr/local/lib/lua/5.3/jeejah/fenneleval.lua'
      no file '/usr/local/lib/lua/5.3/jeejah/fenneleval/init.lua'
      no file './jeejah/fenneleval.lua'
      no file './jeejah/fenneleval/init.lua'
      no file '/usr/local/lib/lua/5.3/jeejah/fenneleval.so'
      no file '/usr/local/lib/lua/5.3/loadall.so'
      no file './jeejah/fenneleval.so'
      no file '/usr/local/lib/lua/5.3/jeejah.so'
      no file '/usr/local/lib/lua/5.3/loadall.so'
      no file './jeejah.so'
    stack traceback:
      [C]: in function 'require'
      /usr/local/share/lua/5.3/jeejah.lua:324: in function 'jeejah.start'
      ./core.fnl:9: in main chunk
      (...tail calls...)
      [C]: in function 'require'
      client.lua:4: in main chunk
      [C]: in ?

- and it doesn't work without it either.
The only semi-successful result I get when I jeejah.start it with :foreground option,
which is not a good option for my case.

On Mon 23 Dec 2019 at 12:43, Phil Hagelberg <phil@hagelb.org> wrote:

> Ag Ibragimov <agzam.ibragimov@gmail.com> writes:
>
>> Okay, I tried this:
>>
>> [...]
>>
>> Connected with Monroe, resumed coroutine, because debug is enabled it
>> printed 'Connected' in the console. But I don't think it's getting
>> into the middleware function at all. I tried typing in the REPL and
>> then resumed coroutine multiple times, nothing is happening.
>
> I pushed a change to Jeejah to move Fennel handling from being a
> middleware to being a custom op, so it's easier to invoke when using
> Jeejah as a library. (This also means you get access to locals-saving
> functionality from the standard Fennel repl.)
>
> I don't have a way to run Hammerspoon, but this works for me as a
> standalone script:
>
>     (local jeejah (require :jeejah))
>     (local jco (jeejah.start 3444
>                              {:debug true
>                               :fennel true
>                               :middleware (fn [f msg]
>                                             (print "something happening")
>                                             (f msg))}))
>
>     (coroutine.resume jco)
>
>     (while true
>       (io.read)
>       (coroutine.resume jco)
>       (coroutine.resume jco))
>
> The while loop at the end is to simulate requiring input to resume the
> coroutine. Note that the `coroutine` module is loaded by default, so
> it's not necessary to require it. Two resumes are required because
> both the outer server receive loop and the inner connection-level
> coroutine need to run.
>
> Hope that helps.
>
> -Phil

Re: Fennel -> Hammerspoon repl

Details
Message ID
<87d0cbt07h.fsf@hagelb.org>
In-Reply-To
<m1h81nhi29.fsf@gmail.com> (view parent)
DKIM signature
missing
Download raw message
Ag Ibragimov <agzam.ibragimov@gmail.com> writes:

> I tried this way and it didn't work for me. I am clearly missing something here.
>
> - I have cloned jeejah repo and did ~luarocks make ./jeejah-0.3.0-1.rockspec~;

I haven't released the changes in luarocks yet; you'll have to manually
install the files in your codebase by copying them in. It should just be
bencode.lua, jeejah.lua, and jeejah/fenneleval.lua.

-Phil
Export thread (mbox)