vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.75k stars 2.16k forks source link

Error when compiling the ui counter example to javascript #7916

Open symil opened 3 years ago

symil commented 3 years ago

I just installed v and ran the counter example of the ui library. It works when I run it with v run counter.v, but fails when I try to compile it to Javascript with v -o counter.js counter.v with the error:

/home/ytawo/prog/v/vlib/strings/builder.v:10:12: error: cannot register struct `strings.Builder`, another type with this name exists

(it also gives me a ton of warnings)

Output of v doctor:

OS: linux, Ubuntu 18.04.5 LTS
Processor: 6 cpus, 64bit, little endian, Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz
CC version: cc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

getwd: /home/ytawo/prog/prototype
vmodules: /home/ytawo/.vmodules
vroot: /home/ytawo/prog/v
vexe: /home/ytawo/prog/v/v
vexe mtime: 2021-01-06 07:48:05
is vroot writable: true
is vmodules writable: true
V full version: V 0.2.1 42e60b8

Git version: git version 2.17.1
Git vroot status: 0.2-318-g42e60b8e
.git/config present: true
thirdparty/tcc status: thirdparty-linux-amd64 7543de81
serkonda7 commented 3 years ago

Big parts of vlib and V UI are not yet ready for the JS backend

danieldaeschle commented 3 years ago

@playXE

playXE commented 3 years ago

This one for sure will not be able to fix in close future. C FFI is required to run gg module which requires us to use node-ffi module or extend NodeJS with pre-compiled dynamic library.

spaceface777 commented 3 years ago

the goal is to make gg work inside the browser by rendering to a canvas.

playXE commented 3 years ago

@spaceface777 running gg in browser should be easier but we still need to run it on the Node backend too.

phillvancejr commented 2 years ago

@spaceface777 running gg in browser should be easier but we still need to run it on the Node backend too.

Curious why you would want to run gg on the Node backend? It makes sense for sake of consistency, but if you want a backend/desktop application why not just compile to an executable and call it done? Why does Node matter especially since Node doesn't actually have any built in functionality for graphics? You're essentially compiling to js so js (Node) can call C instead of just compiling directly to C. I'm guessing there is a valid reason you'd want to do this but I have no idea what it is, aside from consistency in the JS backend's functionality across Node and the browser

JalonSolov commented 2 years ago

The CI runs tests on the js backend using node, so it needs to work with node for that reason.

Personally, I'd rather see node go the way of the dodo, but it's not my call.

esquerbatua commented 1 week ago

Hi @symil, that example doesn't exists anymore, can you send a code to try to replicate?

symil commented 1 week ago

Hello, unfortunately it's been years and I don't have the code on my machine anymore 🙁