一个很好玩的开源库 https://github.com/evilbinary/scheme-lib
scheme-lib 是一个 scheme 使用的库。目前支持 android mac linux windows,其它平台在规划中。
apt-get install freeglut3-dev libgles1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev libalut-dev libopenal-dev libffi-dev
依赖库。make
命令就可以编译,对应平台的文件在bin
目录下。bin
目录,执行source env.sh
,然后运行./scheme --script ../apps/hello.ss
就可以运行例子。
cd scheme-lib/android/src/packages
,在 shell 下执行python sync.py
命令,这样每次修改后,会自动同步 packages 下的代码到手机/sdcard/org.evilbinary.chez/lib
目录下面,这样方便运行了。(import (test) (gles1) (glut) ) (load "/sdcard/org.evilbinary.chez/lib/apps/hello.ss")
;imgui 例子 ;imgui hello,world (define (imgui-test-hello-world) (glut-init) (imgui-init) (imgui-scale 2.5 2.5) (glut-touch-event (lambda (type x y) (imgui-touch-event type x y) )) (glut-key-event (lambda (event) (imgui-key-event (glut-event-get event 'type) (glut-event-get event 'keycode) (glut-event-get event 'char) (glut-event-get event 'chars)) (if (= 4 (glut-event-get event 'keycode )) (begin (imgui-exit) (glut-exit))) )) (glut-display (lambda () (imgui-render-start) ;(imgui-test) (imgui-set-next-window-size (imgui-make-vec2 200.0 140.0) 0) (imgui-begin "evilbinary" 0) (imgui-text "hello,world") (imgui-end) (imgui-render-end) )) (glut-reshape (lambda(w h) (imgui-resize w h) )) (glut-main-loop) (imgui-exit))
运行效果如下:
在手机上输入运行代码可能不方便,所以弄了个配置文件,把需要运行的代码放到配置中会自己加载代码运行。配置文件为config.xml
内容如下:
<?xml version='1.0' encoding='utf-8' standalOne='yes' ?> <map> <string name="debugCode">(import (test) (gles1) (glut) ) (load "/sdcard/org.evilbinary.chez/lib/apps/draw-point.ss") ;(imgui-test-hello-world) </string> </map>
adb push config.xml /sdcard/org.evilbinary.chez/conf/config.xml
打开 scheme app 就可以直接运行啦。
手工添加 Android.mk 和源码文件到scheme-lib/android/src
下命名为 libhadd 的文件夹。 add.c 内容如下:
#include <stdio.h> #include <stdarg.h> int add(int a,int b){ return a+b; }
Android.mk 内容如下:
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) include $(LOCAL_PATH)/../Optimizations.mk LOCAL_MODULE := add LOCAL_SRC_FILES := add.c LOCAL_C_INCLUDES := LOCAL_CFLAGS += -I. -I./c/ LOCAL_CFLAGS += -g -Wall -DANDROID -DINLINES -DGC_MACROS -Wno-unused-parameter -pie -fPIE -fPIC LOCAL_LDLIBS += -ldl -llog -lz include $(BUILD_SHARED_LIBRARY)
执行make android
。
将编译后生成的库android/src/libs/libadd.so
同步到/sdcard/org.evilbinary.chez/lib
目录下,这样能调用外部库了。
调用外libadd.so
库和使用代码如下:
(import (scheme) (utils libutil) ) (load-lib "libadd.so") (define-c-function int add (int int) ) (display (add 100 1234))
1 qinix 2017-06-12 01:57:58 +08:00 via iPhone 似乎是基于 Chez Scheme 搞的,何不分享一下背后的故事和感受 |
2 jakobliao 2018-03-09 17:05:53 +08:00 lisp 世界真小,鸭子全平台推广啦 |
&nbs; 3 evilbinary OP @jakobliao 啦啦啦 |
4 yoyohaha 2018-10-07 10:53:12 +08:00 鸭子,是我 |