Javascript as a secondary language #2008
Replies: 8 comments 6 replies
-
This is awesome, but the point I don't understand is, is JavaScript will to be a transpilator to lua? Because I guess if not, all functions will need to be redefined by cpp. |
Beta Was this translation helpful? Give feedback.
-
no, native javascript support with all of features. Exactly the same as chrome browser and node.js has.
new parser could handle creating a definition for lua and js at once with minimum programmer effort |
Beta Was this translation helpful? Give feedback.
-
I can help implement TypeScript into it if you want. By the way: any solid progress on it? Can you paste some example code? Adding JS could bring great benefits into MTA especially with Promises ❤️. I wish you luck. |
Beta Was this translation helpful? Give feedback.
-
i made working demo, now i'll leave it to discuss how it should be implemented, what features should be enabled, how it should work being organized in general |
Beta Was this translation helpful? Give feedback.
-
As I suggested in private chat with @CrosRoad95 I think that everything should be like in Lua version of MTA's API. So functions like |
Beta Was this translation helpful? Give feedback.
-
Hello! That is a very cool idea to make JS available alongside with Lua in MTASA I would like to suggest type declarations (with JSDoc comments) that has been made from parser functions from mtasa wiki: https://github.com/mtasa-typescript/mtasa-lua-types. Declaration examples: Also I have an example resource that uses mtasa-lua-types (it works with TypescriptToLua): code, more code. P.S. I believe, there will be not so many security issues with JS.. |
Beta Was this translation helpful? Give feedback.
-
@sbx320 wrote on Discord dev server on March 17, 2021:
I agree with sbx's comments. It would also need rigorous testing to take place in any case, compared to the current Lua scripting engine which has been tailored and worked on since the beginning and has seen the battle testing. V8 in MTA has not, and I am unfortunately very skeptical and very critical in terms of security and maintainability. I think it is too much, and MTA should stick with just Lua. I'd rather spend time updating and testing our Lua and figuring out a working migration solution. Adding v8 to MTA does not get my support right now despite the fact that I use JavaScript daily. |
Beta Was this translation helpful? Give feedback.
-
I will follow up @Jusonex answer here.
There's a lot of stuff in our Lua API as well which should've been written in Lua instead of C++. I think if we tried to write as many things as possible in JS we could eliminate most of the context switches.
There's definitely truth to this. But on the other hand JS has a much better ecosystem overall (Code editors / IDEs, TypeScript).
Totally agreed. We should try to make a good and consistent API, with community feedback.
Definitely IMHO. JS has native support for a lot of stuff which I just can't afford in Lua because of the performance hit. Just see how much slower Lua with OOP is in MTA. Although I should add, our Lua API isn't that bad either, and there are definitely ways we could improve both the API and the developing environment. |
Beta Was this translation helpful? Give feedback.
-
Because javascript is popular, have many benefits over lua with almost the same syntax, i decided to make an attempt of adding javascript as a secondary language to mta. I decided to use V8 https://v8.dev/ the same engine that chrome and cef in mta uses. It may bring new people to mta that already know js.
Getting sources and compiling
Sources of v8 should not be inside mta, some of them will catched by mta gitignore what will cause problems while compiling. My suggestion is to make a script that download them from https://chromium.googlesource.com/v8/v8.git/ depend on version set in config file.
Compiling process requires few extra steps over these in mta:
it may be hard for regular contributor to get it work, and just compiling process takes over half a our and requires good tutorial how to do this.
But if you have .dll and .lib files compiled by someone else, compiling takes seconds - and thats approach i suggest.
Every some time, me, or someone else just update .dll and .lib files. We could use these from eg https://storage.googleapis.com/chromium-v8/official/canary/v8-win32-rel-8.9.276.zip but the problem is that whole compilation may get more complex due required usage of https://libcxx.llvm.org/
Compilation may be done in two way:
My vision how it should be implemented
<script src="foo.js" lang="js">
import * as mta from "mta"
mtalegacy.createObject(1337,0,0,0)
. just "mta" can be a js wrapper over legacy functions.isAllowed()
what return whatever acl allows or not this functionPrototype code examples
Branch i'm working on: https://github.com/CrosRoad95/mtasa-blue/tree/Javascript-2
Beta Was this translation helpful? Give feedback.
All reactions