• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

raycmorgan/erl-lua: An Erlang linked-in driver that allows embedding Lua into th ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

raycmorgan/erl-lua

开源软件地址(OpenSource Url):

https://github.com/raycmorgan/erl-lua

开源编程语言(OpenSource Language):

Erlang 53.3%

开源软件介绍(OpenSource Introduction):

Erl-Lua is a library for embedding Lua into Erlang. It provides a simple interface that is very similar to the Lua C API. In the future it will also include a higher level API to simplify things further.

WARNING: This is definitely not fully tested. Still a bunch of work to be done. If you are careful though, it should be pretty stable (no promises though).

Example:

{ok, L} = lua:new_state().
lua:getfield(L, global, "print").
lua:pushstring(L, "Hello from Lua!").
lua:call(L, 1, 0).
% (Lua) => Hello from Lua!

lua:getfield(L, global, "type").
lua:pushnumber(L, 23).
lua:call(L, 1, 1).
{ok, S} = lua:tolstring(L, 1).
lua:remove(L, 1). % always rebalance the stack.. it is the right thing to do!
S. % => "number" 

For more examples, see the tests.

There is also a simple way to run one off simple Lua code snippets:

(continued from above)
lual:dostring(L, "print 'Howdy!'").
% (Lua) => Howdy!

NEW Higher Level API

call (lua_state L, (atom|string) function_name, list arguments, [int num_returned]) - Call a Lua function and return the values.

1> {ok, L} = lua:new_state().
2> lua_erl:call(L, type, [23], 1).
{"number"}
3> lual:dostring(L, "function add(a, b, c) return a + b + c end").
4> lua_erl:call(L, add, [2, 3, 4], 1).
{9}

The strange 4th arg is the number of values the function can return (since in Lua you can return multiple things). If the number of returned values is 1, the argument can be left off.. therefore both of the above could be rewritten:

lua_erl:call(L, type, [23]).
lua_erl:call(L, add, [2, 3, 4]).



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap