LuaJIT FFI 有多难?

发布于 2024-11-02 07:42:13 字数 159 浏览 1 评论 0原文

我最近研究了Lua,它看起来真的很好。唯一令人烦恼的是它缺乏(标准)库。但 JIT 编译器附带了一个很好的 FFI C 接口。

来自java背景,我试图尽可能避免C语言,所以我的问题是:有没有人有过LuaJIT的经验,特别是它的FFI接口,以及为一个几乎没有知识的人建立一个库有多困难C?

I recently looked into Lua and it seems really nice. The only annoying thing is its lack of (standard) libraries. But with the JIT compiler comes along a nice FFI C interface.

Coming from a java background, i tried to avoid C as much as possible, so my question: has anyone some experience with LuaJIT, especially its FFI interface, and how difficult is it to set up a library for someone with little to no knowledge in C?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

献世佛 2024-11-09 07:42:13

对我来说似乎很简单,Mike Pall 在这里有一些很好的教程,lua 邮件列表也包括一些很好的例子,所以也查看档案

Seemed really simple to me, and Mike Pall has some nice tutorials on it here, the lua mailing list also includes some good examples, so check out the archives as well

扎心 2024-11-09 07:42:13

为几乎一无所有的人建立一个图书馆有多困难
C语言知识?

真的很容易。首先,您需要声明您想要使用的函数。然后,加载目标库并将其分配给 Lua 变量。使用该变量来调用外部函数。

以下是使用 C 数学库中的函数 powf 的示例。

local ffi = require("ffi")

-- Whatever you need to use, have to be declared first
ffi.cdef([[
   double powf(double x, double y); 
]])

-- Name of library to load, i.e: -lm (math)
local math = ffi.load("m")

-- Call powf
local n, m = 2.5, 3.5
print(math.powf(n, m))

how difficult is it to set up a library for someone with little to no
knowledge in C?

Really easy. First, you need to declare the functions that you'd like to use. Then, load the target library and assign it to a Lua variable. Use that variable to call the foreign functions.

Here's an example on using function powf from C's math library.

local ffi = require("ffi")

-- Whatever you need to use, have to be declared first
ffi.cdef([[
   double powf(double x, double y); 
]])

-- Name of library to load, i.e: -lm (math)
local math = ffi.load("m")

-- Call powf
local n, m = 2.5, 3.5
print(math.powf(n, m))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文