- https://gist.github.com/kjunichi/bf9569894fac548bf78d8ddf38c56b40
- https://gist.github.com/kjunichi/635bde07580d6de4c0b5e7f66d18dd50
この下のメモの構想をmruby-juliaというモジュールでやり始めた
numpyとかPythonのすごいライブラリをmrubyから扱えるようにすることでmrubyの科学技術計算関連への 応用を探る。
Py_SetProgramName(argv[0]); /* optional but recommended */
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print 'Today is',ctime(time())\n");
Py_Finalize();
Py_Initialize();
pName = PyString_FromString(argv[1]);
pModule = PyImport_Import(pName);
Py_DECREF(pName);
pFunc = PyObject_GetAttrString(pModule, argv[2]);
if (pFunc && PyCallable_Check(pFunc)) {
pArgs = PyTuple_New(argc - 3);
/* pValue reference stolen here: */
PyTuple_SetItem(pArgs, i, pValue);
}
pValue = PyObject_CallObject(pFunc, pArgs);
Py_DECREF(pArgs);
if (pValue != NULL) {
printf("Result of call: %ld\n", PyInt_AsLong(pValue));
Py_DECREF(pValue);
}
jsonでmrubyとpython間でやり取りする。
python2.7-config --cflags
python2.7-config --ldflags
windows版どうしよう。
JulialangのPyCallが参考にならないか
Julialangオンリーで記述されてる可能性がある。
# evaluate a python string, returning PyObject, given a dictionary
# (string/symbol => value) of local variables to use in the expression
function pyeval_(s::AbstractString, locals::PyDict, input_type)
sb = bytestring(s) # use temp var to prevent gc before we are done with o
sigatomic_begin()
try
o = PyObject(@pycheckn ccall((@pysym :Py_CompileString), PyPtr,
(Cstring, Cstring, Cint),
sb, pyeval_fname, input_type))
main = @pycheckn ccall((@pysym :PyImport_AddModule),
PyPtr, (Cstring,), "__main__")
maindict = @pycheckn ccall((@pysym :PyModule_GetDict), PyPtr,
(PyPtr,), main)
return PyObject(@pycheckn ccall((@pysym :PyEval_EvalCode),
PyPtr, (PyPtr, PyPtr, PyPtr),
o, maindict, locals))
finally
sigatomic_end()
end
end
#########################################################################
# Wrapper around Python's C PyObject* type, with hooks to Python reference
# counting and conversion routines to/from C and Julia types.
"""
PyObject(juliavar)
This converts a julia variable to a PyObject, which is a reference to a Python object.
You can convert back to native julia types using `convert(T, o::PyObject)`, or using `PyAny(o)`.
Given `o::PyObject`, `o[:attribute]` is equivalent to `o.attribute` in Python, with automatic type conversion.
Given `o::PyObject`, `get(o, key)` is equivalent to `o[key]` in Python, with automatic type conversion.
"""
type PyObject
o::PyPtr # the actual PyObject*
function PyObject(o::PyPtr)
po = new(o)
finalizer(po, pydecref)
return po
end
end
juliaからlibmruby.soを呼び出せば、Cフリーでjulia<->python<->mrubyが行き来できないかなぁ
- http://qiita.com/kjunichi/items/51127edd684cc646e5ec
- libtrusterdをRustで動かした
- io.jsでmruby実装のhttp2サーバーのtrusterdを動かした
- JulialangにHTTP2サーバーをさせたら