问题标签 [mruby]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
88 浏览

ruby - 未初始化的常量 MRuby (NameError)

我在安装了 Ruby 和 MRuby 的 Ubuntu Server 16.04 上遇到了以下错误,这是什么神秘错误?

Hiredis 是用 H2O 安装和编译的(最新的 2.3),错误仍然存​​在,我没有 Ruby 的经验,谷歌的解决方案没有帮助。

更新:我已替换为简单的代码以简化问题。

源代码:

0 投票
1 回答
91 浏览

ruby - mruby 相当于 begin ... end until

我正在尝试将 ruby​​ 代码库移植到 mruby。在红宝石(MRI)中,我可以做到(不幸的是,写它的人做到了)

执行statement一次直到然后直到condition变为正数。然而,在 mruby 中,行为是不同的,条件是在第一次运行之前评估的,所以这相当于一个while语句。在 mruby 中,这种结构的侵入性最小的替代方案是什么?

附带说明一下,是否可以修补 mruby 以使这种(和其他)行为变得相似?我的意思是有一套现有的补丁可以做到这一点吗?

0 投票
0 回答
38 浏览

mruby - MRuby 中的非阻塞 $stdin.gets()(不是 MRI)

我正在编写一个需要非阻塞读取$stdin.

通常(如果我使用的是 Ruby 而不是 mRuby)我会通过ThreadandQueue类来完成这个。不幸的是,mRuby 本身并没有提供这些,而且在mruby-thread gem中这似乎是不可能的。

如何在 mRuby 中执行 $stdin.gets() 的非阻塞读取,最好不使用自定义扩展?

0 投票
2 回答
245 浏览

ruby - 从 mruby 调用 C 函数

mruby 是否具有与 Ruby 相同的 FFI 功能?如何从 mruby 调用 C 函数?我之所以问,是因为我正在考虑使用 mruby 脚本编写 H20 Web 服务器,但我需要能够从 mruby 脚本调用 c 函数或程序。

0 投票
0 回答
101 浏览

rake - 如何设置 rake 来编译 mruby gem?

我正在尝试按照用于构建 gems的 mruby文档从此处构建示例 gem 。

我在 Mac OS Catalina 上,我已经安装了 RVM 来管理我的安装 mruby。现在which ruby返回/Users/mdorier/.rvm/rubies/mruby-2.0.1/bin/ruby,所以我可以看到使用了 mruby。

上面的示例 gem 有一个 mrbgem.rake 文件,所以即使文档没有解释如何构建 gem,我想rake应该在那个目录中调用。我没有安装 rake,所以我尝试使用 安装它gem install rake,但似乎gem/usr/bin 中的 Mac OS 的本机可执行文件被调用,显然安装了普通的 ruby​​ 的 rake gem。当我调用该 rake 时,它​​在目录中找不到 Rakefile。如果我指定rake -f mrbgem.rake,它会告诉我NameError: uninitialized constant MRuby

我看到 mruby 没有 gem 命令,但似乎有一个可以与 gem 一起安装的 mgem。我安装了它。我看到有一个mruby-rake可用的 mgem,我使用 激活mgem add mruby-rake了它,但它不会改变rake命令指向的内容。

有人可以解释我如何安装和使用正确的 rake 命令来构建这个 mruby gem 吗?

0 投票
0 回答
90 浏览

windows - Calling Mruby library functions in Crystal segfaults on MSVC environment

I am currently working on a way to bind an Mruby interpreter to Crystal projects. However, my current code segfaults on Windows (while running perfectly on WSL Ubuntu) with the 64bit Visual Studio environment and I do not find a solution for the problem.

Everything compiles fine and the program itself works, but as soon as I execute a Ruby command, it crashes (for debug and release builds) with an access violation.

To compile the Crystal code, I wrote a batch script:

The source codes for Crystal and Mruby are in the third_party directory, under the folders crystal and mruby, respectively. Links to the repos are:

https://github.com/mruby/mruby and https://github.com/crystal-lang/crystal

The Crystal binaries are obtained from the Github CI scripts for Windows and were just copied into the Crystal directory.

The config file for Mruby is simply:

The same program written in C does work, so the problem seems to be connected to Crystal somehow:

The C program was compiled using the following line:

I tried to debug the program with Visual Studio, but the debugger does not seem to be compatible with the Crystal-generated code. Changing compiler flags and defines did not help either.

I really have no idea where the problem is and don't know how to fix this or how to find out what causes it.

0 投票
0 回答
42 浏览

ruby - Call super method from C function

I'm writing an mRuby (https://github.com/mruby/mruby) gem. I have a ruby module with methods implemented in C, the module is to be included/prepended into other classes by a user. Now I want to call an inherited (superclass) method from my C function implementing the module method, just like using super in ruby. How do I do that correctly?