pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/jruby/jruby/commit/e64c83f70a73efd5e8d9f0ab76760575e85e5ee2

/> [Truffle] Demo of interop with JS. · jruby/jruby@e64c83f · GitHub
Skip to content

Commit e64c83f

Browse files
committed
[Truffle] Demo of interop with JS.
1 parent 99de0da commit e64c83f

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
```
2+
$ git clone https://github.com/lucasocon/openweather.git
3+
RUBYOPT='-I samples/truffle/interop/weather/openweather/lib -I samples/truffle/interop/weather' graalvm/bin/js samples/truffle/interop/weather/weather.js
4+
```
5+
6+
The demo hangs after printing the temperature, as some Ruby service threads
7+
get stuck and aren't shutting down properly.
8+
9+
The Ruby `temperature_in_city` method has a `this` parameter which it wouldn't
10+
normally have, because JS passes `this` as the first argument.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Interop.eval('application/x-ruby', 'require "weather"');
2+
3+
temperature_in_city = Interop.import('temperature_in_city')
4+
5+
console.log('Temperature in New York now: ' + temperature_in_city('New York') + '℃');
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'openweather2'
2+
3+
Openweather2.configure do |config|
4+
# This is the endpoint and API key from the tests in the Openweather2 gem
5+
config.endpoint = 'http://api.openweathermap.org/data/2.5/weather'
6+
config.apikey = 'dd7073d18e3085d0300b6678615d904d'
7+
end
8+
9+
def temperature_in_city(this, name)
10+
name = Truffle::Interop.from_java_string(name)
11+
weather = Openweather2.get_weather(city: name, units: 'metric')
12+
weather.temperature
13+
end
14+
15+
Truffle::Interop.export_method :temperature_in_city

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy