Lelelo1
(Leo Wetterek)
June 11, 2022, 2:06pm
1
When I build a wasm project I get MyLibrary.a
and MyLibrary.fx
in wasm32 folder. Looking in Node.js docs it says I am supposed to have a *.wasm file.
Using the files from Elements I get:
[CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 21 3c 61 72 @+0]
How am I supposed to use these files, can I use them with Node.js?
mh
(marc hoffman)
June 11, 2022, 6:16pm
2
An .a
is a Static Library. you would use that to compile reusable objects you wanna use in other projects (much like Element RTL is Elements.a
).
To get a runnable Wasm project (Node.js for Browser) you’d want to build a (non-static) module, a Librray
.
The WebAssembly Module project templates should generate the right kind of output.
Lelelo1
(Leo Wetterek)
June 12, 2022, 3:14pm
3
If I understand correctly, Shared Project and Multi-Target Library belong to:
Tab.
And even though I am visiting other tabs like Cocoa, they are still Shared?
Yes Im using those templates and I get appropriate outputs
Lelelo1
(Leo Wetterek)
June 12, 2022, 3:39pm
4
It’s very cool. With the Node.js Module I can declare variables (C# syntax sugar), in Program class:
public string ProjectName { get; } = "NodeJsModuleProject";
public string SharedProjectName => new Library2.Class1().MyText; // referenced
export interface Program{
ProjectName: any;
SharedProjectName: any;
}
They both work to print by calling the built entry.js file with node. Super!
Two other things. It does not seem possible to declare static variables, and also I noticed type is set to any . Is to possible to achieve types?
So it seems I don’t have to create code to call the *.wasm file itself but use the built generated js code around it
mh
(marc hoffman)
June 13, 2022, 12:36pm
5
Lelelo1:
If I understand correctly, Shared Project and Multi-Target Library belong to:
Tab.
And even though I am visiting other tabs like Cocoa, they are still Shared?
Technically, these two apply to any platform, which is why we show them in all tabs, not just the shared one. e.g. you could use a Sharer Project, even if you only ever code for .NET — there’s nothing inherently cross-platform about them, even though they can also be sued to share code between two or more platforms…
Cool.
Static variables/fields should work with the standard “static
” C# keyword.
As for the “any”, I believe that’s just the nature of JavaScript not being typed, on the JS side these classes come thru as JavaScript objects that yo can (try to) call anything on, they will not be strongly-typed as they are on the C# side…
Lelelo1
(Leo Wetterek)
June 13, 2022, 2:46pm
6
Static property declared in Fire with C# don’t show up in the Module.d.ts
export declare class Module {
instance: any;
module: any;
private constructor();
static instantiate(url?: string): Promise<Module>;
Library2_Class1(): Library2_Class1;
Program(): Program;
}
export interface Library2_Class1{
MyText: any;
}
export interface MyWrappedString{
Value: any;
}
export interface Program{
ProjectName: any;
SharedProjectName: any;
WrappedString: MyWrappedString;
}
Also I notice I can wrap primitive types in classes which does get declared.
I hope I somehow can get full typescript typings from the Elements project though
Lelelo1
(Leo Wetterek)
June 13, 2022, 3:06pm
7
enum
and int
don’t get declared and end up being undefined when trying to print it (in Node)
I guess it makes sense everything has to be turned into text?
// Elements
public String EnumTestProperty { get; } = EnumTest.Three.ToString();
public String TestInt { get; } = 12.ToString();
public object TestObject { get; } = "".ToString();
mh
(marc hoffman)
June 13, 2022, 3:13pm
8
Ah, i see. reproduced; it’s not in the interface, but its also not callable,
public string Foo { get { return "foo"; } }
public static string Bar { get { return "bar"; } }
…
console.log(page.Foo)
console.log(page.Bar)
gives “Undefined” for Bar
. i’m not sure if this isn’t as designed though, i’m not familiar with JavaScript and its patterns for static members; I’ll have to check with the team.
mh
(marc hoffman)
June 13, 2022, 3:16pm
10
Hmm,
public int Baz { get { return 5; } }
works fine for me from JS?
Lelelo1
(Leo Wetterek)
June 13, 2022, 3:25pm
11
Correct I probably misspelled. It did still not show up in Module.d.ts though (int), while string, dictionary, callback (Action) does, with any type.
mh
(marc hoffman)
June 13, 2022, 3:58pm
12
Lelelo1:
Correct I probably misspelled. It did still not show up in Module.d.ts though (int), while string, dictionary, callback (Action) does, with any type.
Curious. jic, can i see a test case for this?
Lelelo1
(Leo Wetterek)
June 13, 2022, 4:04pm
13
Sure here the playground project I am using:
Library2.zip (2.8 MB)
mh
(marc hoffman)
June 13, 2022, 4:35pm
14
I see
export interface Program extends RemObjects_Elements_System_Object{
HelloWorld();
ProjectName: any;
SharedProjectName: any;
WrappedString: MyWrappedString;
ProjectNameName: any;
ProjectNameNameName: any;
EnumTestProperty: any;
TestIntA: number;
TestIntB: number;
TestObject: RemObjects_Elements_System_Object;
MyBool: boolean;
}
for
public string ProjectName { get; } = "NodeJsModuleProject";
public string SharedProjectName => new Library2.Class1().MyText;
public static string MyStaticString { get; } = "MyStaticString";
public MyWrappedString WrappedString { get; } = new MyWrappedString();
public string ProjectNameName { get; } = "Nodoject";
public string ProjectNameNameName { get; } = "Nodojasas";
public String EnumTestProperty { get; } = EnumTest.Three.ToString();
public int TestIntA { get; } = 1; // <-----
public int TestIntB { get { return 2; } } // <----
public object TestObject { get; } = "".ToString();
public bool MyBool {get;} = true;
public void HelloWorld()
{
writeLn("Hello World from Node.js");
WebAssembly.Eval("console.log(\"Hello via eval\")");
}
which all looks good?
Lelelo1
(Leo Wetterek)
June 14, 2022, 9:06am
15
I updated Fire, I still don’t get the type declaration. Here is the setup I have:
I get:
export interface Program{
ProjectName: any;
SharedProjectName: any;
WrappedString: MyWrappedString;
ProjectNameName: any;
ProjectNameNameName: any;
EnumTestProperty: any;
}
ck
(Carlo Kok)
June 14, 2022, 6:01pm
17
Where are you looking? When I build your project, in Library2\Module\Bin\Debug\WebAssembly\wasm32 I see module.d.ts with the same definition as marc has?
Lelelo1
(Leo Wetterek)
June 14, 2022, 7:43pm
18
That’s very strange. I removed project, downloaded the zip. Built.
In that folder, I still get C# int variables missing, also the boolean one in the declaration:
export interface Program{
ProjectName: any;
SharedProjectName: any;
WrappedString: MyWrappedString;
ProjectNameName: any;
ProjectNameNameName: any;
EnumTestProperty: any;
}
mh
(marc hoffman)
June 14, 2022, 7:44pm
19
Lelelo1:
pwd gives…
/Users/lelelo1/Projects/Library2/Module/Bin/Debug/WebAssembly/wasm32
What’s the problem with that? that looks correct?
Lelelo1
(Leo Wetterek)
June 16, 2022, 10:53am
20
Yes, I just pasted it to clarify it was the same as ck’s
Could it be the Mono version or something?
mh
(marc hoffman)
June 16, 2022, 12:00pm
21
Unlikely. But aside from what the .d.ts
looks like, what is the actual concrete problem? What piece of code does not work ?