Lua移植到arm上 并实现在arm上 可以让lua脚本调c语言,C语言调用lua脚本
Lua移植到arm上 并实现在arm上 可以让lua脚本调c语言,C语言调用lua脚本
首先参考http://wiki.chumby.com/index.php?title=Lua&printable=yes上的做法,修改lua-5.1.4.tar.gz. 上的Makefile,编译过后会在/src目录下生成可以在arm-linux上可以运行的lua解析器和luac编译器。我们在arm-linux下运行lua脚本,只需要用到lua解析器就ok了,所以,我们把lua cp到我们开发板linux系统上的 /bin目录下就ok了。这样,在开发板上的linux系统就可以自动地找到lua并使用它了。
Lua
From ChumbyWiki
Jump to: navigation, search
Lua is a lightweight scripting language - see the Lua website
Building lua
· download and unpack the lua source distribution lua-5.1.4.tar.gz.
· edit src/Makefile
o line 10
CC=arm-linux-gcc
o line 12
AR=arm-linux-ar
o line 13
RANLIB=arm-linux-ranlib
o line 15
LIBS= -lm $(MYLIBS) -static
o line 99, remove -lreadline -lhistory -lncurses //这里可能行数有点偏差
把这行的内容$(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
改成 $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl "
· edit src/luaconf.h, comment out line 39 (disable LUA_USE_READLINE)
· do:
make linux
arm-linux-strip src/lua
接下来,我们看看如何实现在arm linux上实现让lua脚本调c语言:
1.写一个jiaohu.c文件:
#include <math.h>
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
static int my_foo(lua_State* L)
{
int n = lua_gettop(L);
int isnum = lua_isnumber(L, 1);
int m = lua_tonumber(L, 1);
printf("%d %d %d\n", n, isnum, m);
lua_pushnumber(L,m);
lua_pushstring(L,"foo ret string\n");
return 2;
}
LUALIB_API int my_init(lua_State* L)
{
lua_register(L, "foo", my_foo);
return 0;
}
用 arm-linux-gcc -I/root/lua-5.1.4/src/ -L/root/lua-5.1.4/src/ -shared -fPIC jiaohu.c -o jiaohu.so编译,这样就把可以加到lua上的动态库编译好了。
再写一个lua的调用脚本 test.lua:
package.loadlib("./jiaohu.so", "my_init")()
a ,b=foo(22,33)
接下来就是把jiahu.so 和 test.lua放到arm linux的某个测试用的临时目录下就ok了
然后执行 一下 >lua test.lua
显示 >1 1 22
成功实现在arm linux上实现让lua脚本调c语言了
现在该来看看如何实现在arm linux下如何实现 C调用lua脚本了
先建立一个 test.c文件:
#include <stdio.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
lua_State* L;
int main ( int argc, char *argv[] ){
L = luaL_newstate();
luaL_openlibs(L);
// luaL_dofile(L, "test.lua");
luaL_loadfile(L, "./test.lua");
int iError = lua_pcall(L, 0, 0, 0);
if (iError)
{
printf("error %d \n",iError);
lua_close(L);
return 1;
}
int a = 11 ;
int b = 12 ;
lua_getglobal(L,"sum");
lua_pushinteger(L,a) ;
lua_pushinteger(L,b) ;
int ret = lua_pcall(L,2,1,0) ;
if ( ret != 0 )
{
printf("error\n");
return 1;
}
printf("sum:%d + %d = %ld\n",a,b,lua_tointeger(L,-1)) ;
lua_pop(L,1);
/* 清除Lua */
lua_close(L);
return 0;
}
再建立一个test.lua文件
width=1 ;
height=2 ;
function sum(a,b)
return a+b ;
End
用一下命令来编译test.c文件
#arm-linux-gcc -I/root/lua_tool/lua-5.1.4-armlinux/src/ -L/root/lua_tool/lua-5.1.4-armlinux/src/ -lm -DLUA_USE_READLINE test.c /root/lua_tool/lua-5.1.4-armlinux/src/liblua.a -o test2 -ldl
把生成的test2 和test.lua文件拷到arm linux上运行:
#Lua test2
就会显示#sum:11 + 12 = 23
参考文章:
http://hi.baidu.com/hqwfreefly/blog/item/5724afef3b6018dab31cb1d1.html
http://hi.baidu.com/mikenoodle/blog/item/5fd129dd1069a9de8c102948.html
http://wenku.baidu.com/view/0d557b0416fc700abb68fc73.html
http://www.extgui.com/?p=157
lua编译问题总结
gcc -lm -g -o test test.c /usr/local/lib/liblua.a -ldl
如果少-ldl,那么编译就会报:
gcc -lm -g -o test test.c /usr/local/lib/liblua.a
/usr/local/lib/liblua.a(loadlib.o): In function `gctm':
loadlib.c:(.text+0x35): undefined reference to `dlclose'
/usr/local/lib/liblua.a(loadlib.o): In function `ll_loadfunc':
loadlib.c:(.text+0xc0): undefined reference to `dlopen'
loadlib.c:(.text+0xfc): undefined reference to `dlsym'
loadlib.c:(.text+0x198): undefined reference to `dlerror'
loadlib.c:(.text+0x1bb): undefined reference to `dlerror'
如果少liblua.a ,就会报如下问题:
[wangbin@tuan lua]$ gcc -lm -g -o test test.c -ldl
/tmp/ccCT0d24.o: In function `main':
/home/wangbin/work/tmp/lua/test.c:26: undefined reference to `luaL_newstate'
/home/wangbin/work/tmp/lua/test.c:27: undefined reference to `luaL_openlibs'
/home/wangbin/work/tmp/lua/test.c:29: undefined reference to `luaL_loadbufferx'
/home/wangbin/work/tmp/lua/test.c:29: undefined reference to `lua_pcallk'
/home/wangbin/work/tmp/lua/test.c:32: undefined reference to `lua_tolstring'
/home/wangbin/work/tmp/lua/test.c:33: undefined reference to `lua_settop'
/home/wangbin/work/tmp/lua/test.c:36: undefined reference to `lua_close'
collect2: ld returned 1 exit status
如果少-lm,那么编译结果如下:
[wangbin@tuan lua]$ gcc -g -o test test.c /usr/local/lib/liblua.a -ldl
/usr/local/lib/liblua.a(lobject.o): In function `luaO_arith':
lobject.c:(.text+0xdf): undefined reference to `pow'
/usr/local/lib/liblua.a(lvm.o): In function `luaV_execute':
lvm.c:(.text+0x159a): undefined reference to `pow'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_sin':
lmathlib.c:(.text+0x3e): undefined reference to `sin'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_sinh':
lmathlib.c:(.text+0x6e): undefined reference to `sinh'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_cos':
lmathlib.c:(.text+0x9e): undefined reference to `cos'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_cosh':
lmathlib.c:(.text+0xce): undefined reference to `cosh'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_tan':
lmathlib.c:(.text+0xfe): undefined reference to `tan'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_tanh':
lmathlib.c:(.text+0x12e): undefined reference to `tanh'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_asin':
lmathlib.c:(.text+0x15e): undefined reference to `asin'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_acos':
lmathlib.c:(.text+0x18e): undefined reference to `acos'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_atan':
lmathlib.c:(.text+0x1be): undefined reference to `atan'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_atan2':
lmathlib.c:(.text+0x1fb): undefined reference to `atan2'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_fmod':
lmathlib.c:(.text+0x2db): undefined reference to `fmod'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_sqrt':
lmathlib.c:(.text+0x391): undefined reference to `sqrt'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_pow':
lmathlib.c:(.text+0x3d3): undefined reference to `pow'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_log':
lmathlib.c:(.text+0x450): undefined reference to `log'
lmathlib.c:(.text+0x460): undefined reference to `log'
lmathlib.c:(.text+0x486): undefined reference to `log10'
lmathlib.c:(.text+0x4aa): undefined reference to `log'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_log10':
lmathlib.c:(.text+0x4de): undefined reference to `log10'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_exp':
lmathlib.c:(.text+0x50e): undefined reference to `exp'
collect2: ld returned 1 exit status
Lua移植到arm上 并实现在arm上 可以让lua脚本调c语言,C语言调用lua脚本相关推荐
- lua脚本移植到linux平台,如何将lua移植到arm平台的linux内核
将脚本移植到内核是一件很酷的事情,lua已经被移植到NetBSD的内核中,也有一个叫lunatik的项目把lua移植到了linux内核,只可惜只支持x86,不支持arm,在网上搜索了下,没有找到现成的 ...
- stm32 移植java_把Lua移植到stm32上,效果不错! (amoBBS 阿莫电子论坛)
因为我们产品的需要满足不同行业需求,所以一直在寻找一个脚本语言,以便灵活配置. 前段时间还自己花时间去实现一个C语言解释器,看了一堆编译原理的东西,以及虚拟机等,头都搞大了,把基本功能实现了,但总是不 ...
- arm linux telnet 密码,arm-linux 板子上telnetd的移植
首先在内核中要支持一样东西: 在Character devices中选中Unix98 PTY support busybox中已经可以支持telnetd的命令,我用的是busybox-1.24.1版本 ...
- 嵌入式实训大纲 --上海怡胜信息科技有限公司
嵌入式Linux智能实训大纲 一. 什么是嵌入式 通俗理解,把计算机嵌入到各种设备中,如机械控制设备.汽车控制设备.航天设备.环境监测设备.家电设备等,并且通过计算机来控制设备完成自动化.智能化的操 ...
- 移植gdb到DM368 IPNC中 linux arm gdb
From: http://blog.csdn.net/ghostyu/article/details/8081897 移植gdb到嵌入式的ipnc中,大多数人习惯使用printf调试,但是遇到像&qu ...
- Mobile Lua 6.5 发布,MoSync 的 Lua 移植版本
MobileLua 是 MoSync 的 Lua 移植版本,MoSync 是移动设备上的跨平台开发系统.该项目的目的就是为了在大多数移动身边上运行 Lua 编写的程序. Mobile Lua 6.5 ...
- 网络上所谓的《ARM嵌入式系统入门最好的文章》
一 首先说说ARM的发展 可以用一片大好来形容,翻开各个公司的网站,招聘里面嵌入式占据了大半工程师职位. 广义的嵌入式无非几种:传统的什么51.AVR.PIC称做嵌入式微控制器:ARM是嵌入式微处理器 ...
- 0.基于C++的图像处理算法实现、INTEL CPU上SSE加速、ARM CPU上NEON加速
基于C++的图像处理算法实现.INTEL CPU上SSE加速.ARM CPU上NEON加速 基于C++的图像处理算法在INTEL CPU上SSE加速实现 基于C++的图像处理算法在ARM CPU上NE ...
- STM32移植RT-Thread后的串口在调试助手上出现:(mq != RT_NULL) assert failed at rt_mq_recv:2085和串口只发送数据不能接收数据问题
STM32移植RT-Thread后的串口在调试助手上出现:(mq != RT_NULL) assert failed at rt_mq_recv:2085的问题讨论:http://www.rt-thr ...
最新文章
- HttpUnit学习笔记
- 全国ps职称计算机试题及答案,最新职称计算机考试photoshop练习题
- 查看命令为内置命令还是外部命令
- 操作篇 isis协议实验
- tensorflow安装正确, import tf, the problem is Couldn't find field google.protob.ExtensionRange.options
- vim查找关键字_VIM学习笔记 对话框(Dialog)
- OpenCV-Python实战(18)——深度学习简介与入门示例
- 淘宝前端框架kissyui
- 图像识别实战——天气分类
- 基于java的仓库管理系统_基于Java的仓库管理系统.doc
- 利用excel生成word,批量插入图片、题注、标题等格式
- 关爱的艺术 - 致敬疫情前线奋战的医护人员!
- Python 模拟登录知乎
- 适合小白的Linux入门学习教程,从安装到实操(涵盖各种常用指令,超详细!)
- unity gizmo在游戏中绘制_world machine中文版下载_三维游戏地形软件pc版免费下载3.3026...
- 模拟电子技术(二)基本放大电路
- 雨林木风 Ghost XP SP2 精简版 Y2.0
- 2021个人工作计划
- filezilla显示无法连接服务器,FileZilla 错误:无法连接到服务器
- 下标运算符究竟是单目运算符还是双目运算符
热门文章
- 【Android 电量优化】电量优化 ( 充电状态获取 | 主动获取充电状态 | 广播接受者监听充电状态 | 被动获取充电状态 | 注册空广播接受者获取历史广播 )
- 【Android 性能优化】应用启动优化 ( 阶段总结 | Trace 文件分析及解决方案 | 源码分析梳理 | 设置主题的方案总结 ) ★
- 【数据挖掘】数据挖掘算法 组件化思想 ( 模型或模式结构 | 数据挖掘任务 | 评分函数 | 搜索和优化算法 | 数据管理策略 )
- Wannafly挑战赛3
- Mac下Jenkins+SVN+Xcode构建持续
- Bat 循環執行範例
- java Socket Tcp 浏览器和服务器(一)
- Asp.net中的web.config配置
- 使用LoadRunner测试WMS
- 实际程序调用IndexWriter* writer = NULL