[ 
https://issues.apache.org/jira/browse/COUCHDB-1842?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13695487#comment-13695487
 ] 

Alexander Shorin commented on COUCHDB-1842:
-------------------------------------------

As far as my Erlang knowledge let me read the sources, there need to not just 
eval(<<"lua code">>) but prepare VM state using 
[luerl_emul:set_global_key|https://github.com/rvirding/luerl/blob/develop/src/luerl_emul.erl#L100].
 So we init Lua VM first with [State0 = 
luerl:init()|https://github.com/rvirding/luerl/blob/master/src/luerl.erl#L97], 
then preparing base environmet with [State1 = 
luerl_emul:alloc_table(State0)|https://github.com/rvirding/luerl/blob/develop/src/luerl_emul.erl#L127]
 and then updating it with `luerl_emul:set_global_key`. When environment is 
done, executing Lua code with [luerl:do(LuaCode, 
StateX)|https://github.com/rvirding/luerl/blob/master/src/luerl.erl#L64].

It also looks possible to bypass Erlang functions to Lua VM, so we may use json 
library or some set of functions to work with Erlang's proplists inside.

There are some advanced examples available in [Google 
Group|https://groups.google.com/forum/?hl=en#!forum/luerl].
                
> Lua native query server
> -----------------------
>
>                 Key: COUCHDB-1842
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-1842
>             Project: CouchDB
>          Issue Type: New Feature
>          Components: View Server Support
>            Reporter: Alexander Shorin
>
> [Luerl|https://github.com/rvirding/luerl/tree/develop] - an implementation of 
> Lua in Erlang. It's runs as within separate Erlang process within 
> controllable environment (so we could specify only safe functions for global 
> namespace). It will be awesome to have this in CouchDB as additional query 
> server to Javascript / CoffeeScript which could be enabled by default and 
> utilize all Erlang's features and still be safety for custom code execution. 
> Sure, it could be implemented as standalone CouchDB plugin like GeoCouch, but 
> why not to have batteries included to gather more power?(:
> P.S. Some [presentation video|http://www.youtube.com/watch?v=TolOxVxqoZ8] 
> about.
> P.S.S. License according most active develop branch is [Apache 
> 2.0|https://github.com/rvirding/luerl/blob/develop/LICENSE]

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to