nocturlab / vi-v

Vi-v is a visual scripting UI for vlang. It allows anyone to create their own programs easily without an extensive programming skill.
https://vi-v.fr
MIT License
8 stars 0 forks source link

POC of Vlang library callable like C lib #6

Open shiipou opened 4 years ago

shiipou commented 4 years ago

POC of Vlang library callable like C lib in Android NDK (Or other)

This will help me to know if it better to use V for the main base of the app orif I will use C.

shiipou commented 4 years ago

To use Vi-v on Android or iOS I will use flutter C interop (dart:ffi) That will allow the usage of Vi-v on each mobile devices.

shiipou commented 4 years ago

Here first step of my POC :

The Vi-v lib in V :

Screen Shot 2020-07-20 at 15 42 18

This just contain a test function that will be called in a V exe.

Compile the V version of the Vi-v lib into a C file.

Screen Shot 2020-07-20 at 15 44 48

The command use the V compiler to translate V into C file. It's supported by default in V.

The C file got too many content to easly find how V translate the V code into C.

Screen Shot 2020-07-20 at 15 46 45

Because it include all the V types, structs, and functions. But I did'nt need to see it.

So I've make an empty lib in V and translate it in V to.

Screen Shot 2020-07-20 at 15 48 55 Screen Shot 2020-07-20 at 15 53 30

And I use the diff command to see only the translated code without deps.

Screen Shot 2020-07-20 at 15 58 37

Here I can see V has generate my function vi_v.test() into a C function named vi_v__test();

So I'll generate the compiled lib to the root folder :

Screen Shot 2020-07-20 at 16 05 22

I'm on Mac os, so .dylib is the dynamic library generated. On Linux that must be .so.

To call the lib function on my main program (in V), I just have to include it and to call it.

Screen Shot 2020-07-20 at 15 40 02

But I've got an error on the last step :

Screen Shot 2020-07-20 at 16 40 52
ken0x0a commented 3 years ago

It should work in this way

#include ...

fn C.vi_v__test() // <- add this

fn main() {
  C.vi_v__test()
}
shiipou commented 3 years ago

@ken0x0a Thanks, I haven't updated it, But that will be really great to work like this.

Thanks for the tips, Love to see you following this project.

PS: By the way, Just let you know I now will work at part time on it with the help of a student. I hope to make something appear before September.

shiipou commented 3 years ago

I'm little late, nothing appear in September because of some points that make me upset with my app. I want the best approach, so I've restarted almost everything.