#2020征文-開(kāi)發(fā)板#移植lua到鴻蒙—在鴻蒙上用lua跑Hello World
想了解更多內(nèi)容,請(qǐng)?jiān)L問(wèn):
51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)
https://harmonyos.51cto.com/#zz
慣例先放hello world

本項(xiàng)目地址: https://gitee.com/hiharmonica/lua
下載能在鴻蒙上跑的二進(jìn)制文件
準(zhǔn)備環(huán)境
1. 安裝 docker
2. docker pull ystyle/open-harmony
- ps: 本文使用與鴻蒙系統(tǒng)一同編譯的方法。 如果自己有本地環(huán)境,可以把lua項(xiàng)目放鴻蒙代碼目錄里(或者使用軟接連)
下載lua官方代碼
- mkdir -p ~/code/ohos/
- cd ~/code/ohos/
- git clone https://github.com/lua/lua.git
編寫(xiě)B(tài)UILD.gn文件
因?yàn)橐c系統(tǒng)一起編譯, 為了方便,直接用替換掉示例的方法,這樣就只需要寫(xiě)一個(gè)BUILD.gn就好了
- # Copyright (c) 2020 YSTYLE(lxy5266@live.com)
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- import("//build/lite/config/component/lite_component.gni")
- import("//build/lite/ndk/ndk.gni")
- static_library("hello_world") {
- sources = [
- "lapi.c",
- "lauxlib.c",
- "lbaselib.c",
- "lcode.c",
- "lcorolib.c",
- "lctype.c",
- "ldblib.c",
- "ldebug.c",
- "ldo.c",
- "ldump.c",
- "lfunc.c",
- "lgc.c",
- "linit.c",
- "liolib.c",
- "llex.c",
- "lmathlib.c",
- "lmem.c",
- "loadlib.c",
- "lobject.c",
- "lopcodes.c",
- "loslib.c",
- "lparser.c",
- "lstate.c",
- "lstring.c",
- "lstrlib.c",
- "ltable.c",
- "ltablib.c",
- "ltests.c",
- "ltm.c",
- "lua.c",
- "lundump.c",
- "lutf8lib.c",
- "lvm.c",
- "lzio.c"
- ]
- include_dirs = [
- "include",
- ]
- }
- lite_component("camera_app") {
- target_type = "executable"
- features = [
- ":hello_world",
- ]
- }
- ndk_lib("app_sample") {
- deps = [
- ":hello_world"
- ]
- head_files = [
- "include"
- ]
- }
static_library里的source參照l(shuí)ua/makefile
編譯腳本
創(chuàng)建編譯腳本build-ohos.sh文件
- cd ~/code/ohos/lua
- touch build-ohos.sh
- chmod +x build-ohos.sh
文件內(nèi)容如下
- set -e
- rm -rf ./out ./bin
- docker run --rm -ti \
- -e HARDWARE=ipcamera_hi3516dv300 \
- -v ${PWD}/out:/OpenHarmony/out \
- -v ${PWD}:/OpenHarmony/applications/sample/camera/app \
- ystyle/open-harmony
- mkdir -p ./bin
- cp ./out/ipcamera_hi3516dv300/bin/camera_app ./bin/lua
- tar -zcf lua-5.4.2-ohos.tar.gz ./bin
- echo 'build success!'
與鴻蒙一起編譯,這里使用我之前的docker鏡像
- cd ~/code/ohos/lua
- ./build-ohos.sh
- # 看到 ohos ipcamera_hi3516dv300 build success! build success! 就編譯成功了。
- 編譯后軟件在鴻蒙的 ./out/ipcamera_hi3516dv300/bin/camera_app
- 腳本會(huì)把lua單獨(dú)打包出來(lái)
- 單獨(dú)的lua可執(zhí)行文件在bin目錄
### 演示




本文鏈接:http://ystyle.top/2020/11/07/porting-Lua-to-openharmony/
博客內(nèi)容遵循 知識(shí)共享 署名 - 非商業(yè)性 - 相同方式共享 4.0協(xié)議
想了解更多內(nèi)容,請(qǐng)?jiān)L問(wèn):
51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)
https://harmonyos.51cto.com/#zz