New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for the Julia programming language. #23
Comments
OK, Thank you moving from twitter to here. I think julia maybe work with SL4A, Next, you need to package the deploy app and Please fork this project or SL4A language branch, |
@Ismael-VC p.s. good looking on running arch. i run arch too! :D |
@ainsophical yes definitely! Thank you so much, that would be awesome, please let me know what I can do from the Julia side in order to help you make this possible. 👍 The Julia syntax is easy! 😄 It's a little outdated (v0.3) but for that introductory tutorial, syntax has remain the same AFAIKT. |
not really interested in julia but i think it would be cool to get more interpreted languages hooked into SL4A for a broader audience of this really cool app... we need to hook julia into the known language list in SL4A. (Took care of this.... easy) We need to compile Julia into an arm executable so it can run on android, and add any modules that are not c based. Then package this all up in an apk. I can start working on this as I want to get the process down so I can get other languages working in the future... We also need an android module for julia. If you want you can convert this python android module to julia. Once I get the template going we can test it and see how it works...
|
@ainsophical where does |
Oh ok, I found it at:
Is this a 🪲? |
Julia ARM executable, the one I've tested on Android: |
Three Julia packages would be needed, all are 100% julia code: |
i see what you mean and it didn't make much sense to me either. it's not a bug but i can't honestly say i know exactly how it works with a bit of prying into the code yet. i ran the android.py module with that conditional commented out and got this error in logcat.
i found this in JsonRpcServer.java
inherited through the socket connection somehow? not sure but yes that part is needed... |
@ainsophical based on the Python and Ruby versions, I've come up with this: __precompile__() # Allow for whole module precompilation.
module AndroidConnection
# It seems only this external package is needed (and it's dependeny `Compat.jl`).
using JSON: json
export Android
# Types don't own function methods.
type Android
client::TCPSocket
id::Int
end
# Type constructor
function Android()
handshake = ENV["AP_HANDSHAKE"]
_authenticate(handshake) # WTF!?
host = ENV["AP_HOST"]
port = parse(Int, ENV["AP_PORT"])
client = connect(host, port)
id = 0
new(client, id)
end
function _rpc(a::Android, method::Symbol, args...)
a.id += 1
request = json(Dict("id" => a.id, "method" => method, "params" => args))
println(a.client, request)
flush(a.client)
response = readline(a.client)
JSON.parse(response) # Last value is returned.
end
# In Julia `Base.getfield` (`foo.bar`) can't be extended "yet", instead
# `Base.getindex` (`foo[bar]`) is used.
Base.getindex(a::Android, method::Symbol) = (args...) -> _rpc(a, method, args...)
end # End module. Still I can't understand how does From all the versions found here, for several languages, none of them seems to be defininf their own |
This is the Ruby version: AP_PORT = ENV['AP_PORT']
AP_HOST = ENV['AP_HOST']
AP_HANDSHAKE = ENV['AP_HANDSHAKE']
require 'json/pure'
require 'socket'
def trap(*ignore)
# Trap does not work on Android.
end
class Android
def initialize()
@client = TCPSocket.new(AP_HOST, AP_PORT)
@id = 0
_authenticate(AP_HANDSHAKE) # WTF!?
end
def rpc(method, *args)
@id += 1
request = {'id' => @id, 'method' => method, 'params' => args}.to_json()
@client.puts request
response = @client.gets()
return JSON.parse(response)
end
def method_missing(method, *args)
rpc(method, *args)
end
end |
I would expect this to fail like this: julia> ENV["AP_HOST"] = "google.com"
"google.com"
julia> ENV["AP_PORT"] = 80
80
julia> ENV["AP_HANDSHAKE"] = :whatever
:whatever
julia> using AndroidConnection
julia> Android()
ERROR: UndefVarError: _authenticate not defined
in call at /home/ismaelvc/Android.jl:19 |
I'm also unsure as to when to increment def _rpc(self, method, *args):
data = {'id': self.id,
'method': method,
'params': args}
request = json.dumps(data)
self.client.write(request+'\n')
self.client.flush()
response = self.client.readline()
self.id += 1 # WTF!?
result = json.loads(response)
if result['error'] is not None:
print result['error']
# namedtuple doesn't work with unicode keys.
return Result(id=result['id'], result=result['result'],
error=result['error'], ) def rpc(method, *args)
@id += 1 # WTF!?
request = {'id' => @id, 'method' => method, 'params' => args}.to_json()
@client.puts request
response = @client.gets()
return JSON.parse(response)
end |
i dont have it figured out yet either but one thing you should know that there is a language class in SL4A that can be extended for each new language. Each one has to have something that looks for the import statement and the initialization of the droid object like so... it might be overriding the error as sl4a controls the interpreter as well and handles the statement itself. ive only been working on this project for a couple months now and its a bit to get a good handle on the internals so pardon not having a definite answer yet.
ill report back when i find out where this leads to get to that snippet i showed you before as it was the only line in the code that was as far as the increment, i dont think it matters much whether it starts at zero or one / before or after the request. it was probably just the preference of the person that coded the specific language module.. the rpc receiver loop doesnt look like it cares just so long as it has an id to pass as a param with each call to it.. |
This file has tests for the handshake: This lines are also relevant, inside |
Ok, I think I got this:
__precompile__()
module SL4A
import JSON
export Android
const HOST = ENV["AP_HOST"]
const PORT = parse(Int, ENV["AP_PORT"])
const HANDSHAKE = ENV["AP_HANDSHAKE"]
typealias String AbstractString
type Android
client::TCPSocket
id::Int
function Android()
droid = new(connect(HOST, PORT), 0)
droid(:_authenticate, HANDSHAKE)
return droid
end
end
function Base.remotecall_fetch(droid::Android, method::String, params...)
request = JSON.json(Dict("id" => droid.id, "method" => method, "params" => params))
println(droid.client, request)
flush(droid.client)
response = readline(droid.client)
droid.id += 1
JSON.parse(response)
end
Base.call(droid::Android, method::String, args...) = remotecall_fetch(droid, method, params...)
Base.call(droid::Android, method::Symbol, args...) = call(droid, string(method), params...)
end
package com.googlecode.android_scripting.language;
public class JuliaLanguage extends Language {
@Override
protected String getImportStatement() {
return "using SL4A\n";
}
@Override
protected String getRpcReceiverDeclaration(String rpcReceiver) {
return rpcReceiver + " = Android()\n";
}
@Override
protected String getNull() {
return "nothing";
}
@Override
protected String getApplyOperatorText() {
return "(";
}
@Override
protected String getLeftParametersText() {
return ", ";
}
} |
Continues discussion at Twitter:
There is a very active chat room for the Julia language, here!
The text was updated successfully, but these errors were encountered: