part-cw / lambdanative

LambdaNative is a cross-platform development environment written in Scheme, supporting Android, iOS, BlackBerry 10, OS X, Linux, Windows, OpenBSD, NetBSD, FreeBSD and OpenWrt.
http://www.lambdanative.org
Other
1.4k stars 86 forks source link

static lib for existing native iOS apps #107

Closed ildarsharafutdinov closed 8 years ago

ildarsharafutdinov commented 8 years ago

hi,

I'm looking for a way to create static libs with lambdanative and use them in existing iOS apps in obj-c/swift.

Is make payload the right way to go?

Any ideas are greatly appreciated.

mgorges commented 8 years ago

Hi @ildarsharafutdinov - make payload is part of the regular application compilation process and won't result in a shared library. We'll need to think a bit more about how to expose interfaces to create libraries you envisioned. Give us a few days to think about it and then get back to you. Thanks Matthias

ildarsharafutdinov commented 8 years ago

@mgorges,

Thank you for the reply.

I'll explain a bit more what I want to achieve. It's ok for me to create native UI with iOS/Android tools. From what I've seen so far this is the only option to create UI that feels good on target platforms.

However, I want to write internal app logic once. This logic doesn't contain UI part and can be done in portable way. Dropbox team has chosen c++ and implemented djinni tool to generate bridging code. Personally would prefer scheme instead of c++. There is also a mocl tool which looks pretty neat for common lisp.

Gambit + lambda native seems to be almost there as well. The only option left is to enable lambda native without main function.

ildarsharafutdinov commented 8 years ago

@mgorges,

any ideas on what to use instead of make payload?

clpetersen commented 8 years ago

Commit 0fd9226 adds basic support for this functionality. make payload does what you want. You can make an app with your Scheme logic, and some C declared functions, e.g.

(c-define (c-plus x y) (int int) int "scm_plus" "" (+ x y))

This could be placed either in a console app (like DemoConsole) or in a gui app. When you do ./configure <YourApp> ios followed by make payload, the payload library is generated for iOS (or whatever other platform you want), and the last line of the build log points to it, something like == /Users/chris/Library/Caches/lambdanative/ios/armv7/lib/libpayload.a. Copy this file into your third party toolkit, and invoke your logic from C like so

void lambdanative_payload_setup();
void lambdanative_payload_cleanup();
int scm_plus(int,int);
...
lambdanative_payload_setup();
...
printf("1 + 2 = %i\n", scm_plus(1,2));
...
lambdanative_payload_cleanup();
...

You'll need to work out the dependencies of the static payload library. It is for the most part self-contained, but does use some standard OS libraries/frameworks depending on the modules you include in the app. Note that some modules trigger loader side changes that are not reflected in the payload library. Your milage will vary.. this is not the intended use of the lambdanative framework, but if you really just write clean Scheme logic, you should be fine.