lua如何嵌入java_嵌入时如何使用LuaJIT的ffi模块?

我正在尝试将LuaJIT嵌入到C应用程序中 . 代码是这样的:

#include

#include

#include

#include

#include

int barfunc(int foo)

{

/* a dummy function to test with FFI */

return foo + 1;

}

int

main(void)

{

int status, result;

lua_State *L;

L = luaL_newstate();

luaL_openlibs(L);

/* Load the file containing the script we are going to run */

status = luaL_loadfile(L, "hello.lua");

if (status) {

fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1));

exit(1);

}

/* Ask Lua to run our little script */

result = lua_pcall(L, 0, LUA_MULTRET, 0);

if (result) {

fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1));

exit(1);

}

lua_close(L); /* Cya, Lua */

return 0;

}

Lua代码是这样的:

-- Test FFI

local ffi = require("ffi")

ffi.cdef[[

int barfunc(int foo);

]]

local barreturn = ffi.C.barfunc(253)

io.write(barreturn)

io.write('\n')

它报告错误如下:

Failed to run script: hello.lua:6: cannot resolve symbol 'barfunc'.

我四处搜索,发现ffi模块上的文档确实很少 . 非常感谢 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值