I use Google V8 engine to embed Javascript into my game for scripting. As interface to my native code, I already registered some C++ functions to the scripting context.
In the native code, I make intense use of the C++ library GLM which adds vector types and geometry functions. The naming is in a style that may be known from shader code, for example vec3
, uvec2
, normalize()
, length()
, and much more.
Now I would like to make these types available in scripting. That would be useful because of both, the geometry functions and the vector types. Especially, I want to use the vector types as parameters in the C++ functions I mapped to the Javascript context. At the moment I'm using arrays like float[3]
instead of the vectors like vec3
.
So I am looking for possible ways to bring GLM functionality into Javascript. This is what I can think of.
- Create the most important types by hand, either in a Javascript file or injected from C++ code using object templates. Unfortunately, I cannot do this for all of the many functions in GLM. But it would better than nothing.
- There might already be a GLM port of Javascript, which I haven't found on the internet.
- I could pick a different geometry library for use in Javascript. For bound C++ functions, I'd have to translate their types into GLM ones then.
- What can you think of...
Maybe there is a cool way to all the functionality of GLM over to Javascript. Are there things like C++ to Javascript source code converters? Or automatically binding a whole C++ namespace to scripting? I don't think that is possible. But Javascript is such a dynamic language, there must be a way to make the GLM types available for it.
What ways are there for making the vector types, and preferably also the useful geometry helper functions, available in scripting?