Closed Lingelo closed 3 years ago
If there is an evolution to be made in your project, I can try to do it.
hey! You need to create headers similar to https://github.com/andrei-markeev/ts2c-target-esp-idf/tree/master/headers I cannot see these headers in your project.
So smth like
declare module "headers/gb/gb.h" {
const J_START: number;
function waitpad(button: number): void;
}
put this in a file headers/gb/gb.h/index.d.ts
and then
import { waitpad, J_START } from 'headers/gb/gb.h';
console.log("Press START!\n");
waitpad(J_START);
console.log("> Good!");
the IDE should actually see the declaration file, so providing all code completion and everything.
Thanks I will try. Headers come from the GameBoy C SDK : https://github.com/andreasjhkarlsson/gbdk-n/tree/master/include/gb
Hi,
I tried the solution here : https://github.com/Freuhlon/gb-projects/tree/master/hello-world .
I still have the same error that you can see in hello.c : / Unsupported function call: waitpad(J_START) /;
I also tested with the example in your project and I have the same result on the functions mapped in the modules.
Do you have any idea what's going wrong?
Thanks
I'll have a look
Hello! Sorry for the delay, I just got my hands to it.
You're absolutely correct, there seems to be a bug. I was doing a lot of stuff with functions, adding closures and stuff, so it seems I broke this external import functionality while doing that. It does work with older version of ts2c though.
I wanted to finish my current work before returning to bugs. That can take quite some time.
Please use v2.2.2 in the meanwhile, i.e. npm i -g ts2c@2.2.2
and ts2c example.ts
- I tested and this seems to work with that simple example you provided.
Thanks for reporting!
Hi Andrei,
Thank you for your answer. Version 2.2.2 seems to be incompatible with my initial request. This produces the following file :
#include <stdio.h>
int main(void) {
/* importing other TS files is not yet supported: import {J_START, waitpad} from "headers/gb/gb.h"; */
printf("Hello world\n");
printf("Press START!\n");
waitpad(J_START);
printf("> Good!\n");
return 0;
}
I need headers too.
I will wait for the next versions. FI : Versions 2.2.3, 2.2.4, 2.2.5 and 2.2.6 do not work with my file (these versions produce an error when transpiling).
This is very strange:
actually let me publish the example that I hacked together, maybe it will help you
here you go: https://github.com/andrei-markeev/ts2c-target-gbdk-n
cd ts2c-target-gbdk-n/examples
npm i
npm i -g ts2c@2.2.2
this should work for sure!
Hi Andrei, Oh .... You are right! I was wrong about the global dependencies. Improper handling ...
Sorry.
Thanks for your work !
Np. I am very interested in practical applications of TS2C, obviously 😄
For now what I see in microcontrollers, types of variables are very important and TypeScript is usually not granular enough in this sense. This is why I had to use the /** @ctype ... */
syntax in the declaration - but even that is not always enough.
Check out thumby.ts for example, the generated thumby.c uses int16_t
everywhere which might actually work in this particular case, because it is defined as char
by default, but when you need more variance, or when you need to use e.g. unsigned values, it might not work anymore, depending on CPU architecture.
TS2C currently not working particularly well in these cases and definitely needs some improvement. And there's a lot of other work as well...
I had some time to dig deeper into that, and here's what I found:
ts2c-target-
, in this case, first part of module name is ignored, and other parts are used in #include
. For example, import {abs} from "ts2c-target-test/stdlib.h";
will produce #include <stdlib.h>
.function waitpad(button)
will not work, but function waitpad(button: number): number
will.d.ts
file where TypeScript can find it according to normal module resolution rules. For example, node_modules/ts2c-target-test/stdlib.h.d.ts
.Having these three conditions met, it will work also with latest version of ts2c (btw I published 2.2.9 recently).
I wonder, should I publish ts2c-target-gdbk-n
to npm? Then you could simply npm i ts2c-target-gdbk-n
and then import {waitpad} from "ts2c-target-gdbk-n/gb/gb.h"
...
I will close this because it seems that it works as intended after all 😄
Thank you so much Andrei
Hi Andrei,
I did a small project that uses TS2C. This project allows you to transpile TS code and build a gameboy rom. If you are interested you can see it here: https://github.com/Freuhlon/gbts
First of all, I have a question for you:
I'm looking to do something similar with the GameBoy SDK. I would like to produce the following code:
Taking inspiration from the code in the example, I made the following code:
Transpiled to:
I would like to know how you did to call the code of the headers in your typescript code.
Is there a way to call this code (
waitpad(J_START)
) from the headers? In other words, make the transpilator more permissive.thanks & regards / Merci beaucoup