New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add JavaScript as an alternative to Lua #2169
Conversation
inspector things Remote debugger
@Disinterpreter, clever community 🤣 "Чья бы корова мычала". https://luarocks.org/modules/daelvn/isodd clever humanity |
@AlexTMjugador, Who want xml, lua, pain - use xml, lua. Who want json, js, sugar - there should be an opportunity do it. JLM. Lua has very lot of "handmade required" + MTA limitation (example: i cnow about luarocks, but more packages using "require" ("require" disabled in mta and for use package have to again make "handmade" (example - compile to single file))) Lua + MTA not supported by IDE. Example: How to debug variable in MTA ? - restart resource and looks to debug minichat - its looks as joke. C++ not my lang... i dont know how MTA works now. I just see bridge as resolve some problem as nativescript. My things is Lua best for devs who want thouch history, make handmade "class" and 100 bicycle, stepped on a 100 rake. |
@websharik the only reason for me to support this pr would be because of webassembly also there is one very important aspect in this pr: and this is the very big advantage of Lua it's very easy to safely sandbox it and this is were javascript engines doesn't have the greatest reputation specially with exploits like spectre and meltdown in recent years |
This repo hasn't contain serious context, moreover it was created by fun (look at the license) an it has 20 downloads versus 400k
The same must be on the server side as we remember. Or we need to remove some of restrictions for server side lua (that's impossible) |
I think the administration and security part should not be ignored either. The KISS principle and the low overhead in the configurations makes MTA relatively easy to maintain and manage. The fact that you can specify which ports are to be used and how many slots the server has with just three start arguments is very handy. If the implementation of JavaScript using V8 should really bring a benefit with its one million packets, then certain restrictions have to be lifted -- which would contradict the principle mentioned above and would have to be implemented cleanly again, to give the providers something to work with. One would have to think about a concept like Deno in my opinion, that certain functions are available only if they were explicitly permitted. |
Change the MTA Team mind... P.S You know, I'm not against to see JS in MTA. I'm just trying to transparent the MTA Team's vision on the problem overall. All of this depends of MTA security policy, if you want to see good JS implementation in MTA, you must solve this in Lua. |
Most repos of lua hasn't contain serious context. Your not should use every repos from npm in your prod, if your can make better or lighter and you have time to do it (best - send pulll to "bad" repo to make it greate again, its save time for next devs). When your making MWC (minimal working product) or don't feel like writing a bike some as that repos can be usefull + this approach will help to split up the code and remove duplication functional inside project between diff packages, its make project more light. All perfect.
I think we need to see browsers. Any browser using JS and its safe (they limit some modules, add rules to use it (mic, cam, geo, push), and add self scripts (window object, DOM...)). Spectre and meltdown was fixed and touch not only JS becouse they based on CPU caching (MMU). Your can google about that for more info... V8 have included "Inspector protocol" for remote debuging. Lua... i hope too. @xNevo, The KISS stay will be. You dont should know all server parameters to start server, new parameters should be default with safe values. |
If we wanna talk about the place of Lua in the world, we can it do, of course, but it's better to move it in Discussions.
Just a lie, one of the best examples of using Lua here: https://habr.com/ru/post/321864/ Lua has many cool and modern modules for: postgres, kafka, discord, cassandra, even clickhouse and of course Tarantool (which uses Lua too). But anyway as I've told before. We should solve the "secure" problem in serverside before we can discuss about modules. Anyway, if you want full power of Lua or JS on your serverside, you need to change MTA Teams' mind. |
btw, you CAN'T just use that libs and this means: many powerfull/good libs for lua + You're not allowed to use them = there is no libs |
@ERAGON007, Now i use TypeScriptToLua to complite TS (and js) to lua. And many libs from npm can be converted too and nice working (tested). But its so raw project and has issues and some issues cant be resolved for lua5.1 ex: Promise tests down. Now i have no desire to make so projects/resources for MTA, becouse current version MTA SA has very lot mistakes/traps for developers. Any my idea was trapped with "MTA disallows" etc... old lua version (because old luacs will breacks), "limitation" lua (as disable "require"), "limitation" browser (as local/remote working mods, "security...security...security" security is good but MTA is very secured (pentagon is envy), and more more any... Some big projects partical resolve with custom launchers, i not ready learn c++ to make custom luancher to fix MTA Team mistakes to nice developming resources. I waiting MTA team reaction for GTA SA Remasted with hope for MTA Remasted with at least latest Lua5.4/JIT and maybe i come back to MTA developing. |
hmm, that's not a bad idea btw you know that converting/transpilling that JS libs into Lua code actually can't be faster than a code that is purely written in Lua. security in MTA is much better than similiar opponents (like SA:MP, FiveM, IV:MP) BUT this security shouldn't be some bunch of limitations for developers (this disables usage of so many libraries) problems for using ONLY Lua for developing resources is you can't use a debugger so you have to restart the resource you wanna debug and just put some and you have to do that for all your needed variables! a real pain and we can't properly use OO features in Lua opponents like FiveM do have more than one language to their dev API's and leaves the developer itself to choose between what you can and want to use. for example you can use class library project from but in mta things are different and almost all of them because of security. every day we see people in mta community suffer from lack of threads/classes/Intellisense from their IDE while developing my idea is to merge this PR when it's ready for TESTS and just put an option in and the rest of bugs/features will be reported by people they use JS on MTA |
Even though that for various reasons it's already highly unlikely for MTA to ever natively support another scripting language (with natively i mean like, look at what Slipe - C# scripting in MTA accomplished without MTA changing things around.. a transpiler or something like Slipe doesn't have to be native, someone can make it for Javascript as well), i also want to mention additional concerns. MTA invested a lot of AC team manpower into modifying Lua related stuff and integrating anti-cheat closely with Lua implementation in order to defend against various exploits, Lua injection methods and such. However, this was done years ago, over the span of years, by the lead AC developer (ccw) that no longer has enough free time to do that all over for another language. We also currently don't have a talented developer like him to do it instead, such a developer must obviously be part of AC team/MTA team and have affinity and skills for it. So what im trying to say, the reality nowadays means implementing a new language comes with a huge security penalty. There's probably going to be some bollocks like "Java code injector", for example, and even if we patch the initial methods it will take us years to catch up to the same level of security as we have grown for Lua, over many years. Not to speak about other obstacles like years of scripting documentation/tutorials, wiki entries and such being dedicated to Lua in MTA. Even more reasons to make adding another scripting language a difficult task to accomplish were written in here, but even more so in the tons of discussions within our community/forum topics about this matter. Lua is also not bad at all for MTA, you can see that MTA barely has any limits to creativity as we've had full game conversions being made by people (the unimaginable) and it really does suffice for flexibility, features and possibility.. the real reason behind suggestions to replace Lua, or add a second language, is that different people have different preferences and experience with other languages, and are thus opinionated and easy to say using Lua for MTA was a mistake. Just learn lua, master it, then learn to love it.. and you'll get as far in MTA scripting as you want to imagine. But i dont expect MTA to make certain sacrifices, and sadly we can't keep everyone happy. As a side note to @CrosRoad95, it will cause much less disappointment to first get the discussion/decision and outlook on a suggested feature in order before spending so much time on starting to implement things like this. I mean, for yourself, in case you see this PR as wasted effort. Edit: check out Typescript for MTA, it was sent by NanoBob (the author of Slipe, C# in MTA) when asked about doing something similar as he did but then for Javascript. So apparently, someone already did that, but we don't know about the results with it yet, or if it's as feature & documentation-complete as Slipe is. |
Thank you for mentioning MTASA TypeScript project. Few words about it
MTASA TypeScript does not use JavaScript in MTASA runtime. It is based on language transpiling and TypeScriptToLua. So, the pipeline (for user) is being like:
There is:
I have made every effort to make types fully-compatible with MTASA Wiki documentation. Features
Few caveats about it
ConclusionI'm open to discuss the project in the project discord or in the issues. If you have any questions, ideas or suggestions, you are welcome. |
https://github.com/Jusonex/MTATD ???? |
So the logic is : "Don't touch it if it's working" using Lua forever itself is a sacrifice, you know it sucks. MTA teams main goal is to provide a nice security right? that's nice but not if devs get limited and now imagine i wanna use "PostgreSQL" as an alternative for "MySQL/MariaDB", i must use C++ for it because of these limitations at least you could've given Lua library a bit more permissions for ONLY server-side. this is not the Lua people worldwide using. we can't get help from global Lua community - can't use libraries and etc... and the libraries that are usable in mta, you'll need some time to put all of it in a single Lua file and sometimes people give up (including myself) At least give MTA users some respect and let them choose to turn a feature like using JS this is what happens to MTA features over time using a language that's not popular enough = lesser people will contribute = no maintenance = project dies over time just like what happened to MTA's almost dead feature (Modules) |
Not only C++. You can implement your own backend and use REST API to communicate 😃 |
What's difference between JS and Lua if you cannot use denied libraries like in Lua?
Say it to thousand developers of Roblox, please |
But using it as module is a bit different I guess 🤔, right? Edit: Not only Postgres even mongo can be awesome |
If we're going to do that, we need to tell Fivem devs too right? btw it's a similiar project to mta https://docs.fivem.net/docs/support/server-debug/ i don't think people like to restart a resource a thousand times to debug it. even module sdk on github repo is outdated :) |
I see you want to push a certain sentiment, but from my last reply it was already clear that the security aspect is not the reason for a second language not to be implemented.. of which the reasons for it not being the (main) reason, should also be cleared up in my previous post. My reply was actually prompted by yours (you mentioning a lot about "security limiting developers" - the sentiment) to give some clarity about that aspect, but never was it ever among the main obstables towards implementing a second language.. however, having mentioned those concerns as well is good for the sake of completion during this discussion. The main and other real obstacles were given in here, and throughout many other discussions for "add another scripting language to MTA" in the community throughout the last couple years. No one mentioned anything regarding security/AC being yet another potential obstacle, before the discussion had already practically ended in "Too many problems with going ahead and adding another scripting language". Btw, your sentiment isn't very pleasurable.. please stop acting like MTA is deliberately limiting creativity/possibilities of developers, or specifically doing anything (serving "one of the main goals" as you implied) and taking that for granted as a consequence. Also, about the rest of your comments from the same post as my quote:
However @ERAGON007, to keep this discussion useful & prevent it from getting derailed into an argument/word againt someone else's word, please talk about the actual and main obstacles towards implementing another scripting language, that negative sentiment you hold by now has gotten its due attention and answers. Also note that the oversight reply of MTA team in this issue (here) can be useful to understand some of the obstacles.. including to read the one after it, and better also read all other ones given in here and past discussions about adding another scripting language. |
As I said before, MTA gives you You try to compare JS with thousand libraries with restriced mta lua. Give me pure lua and I can work with postgres,mongo, etc... not a problem, really. Need you JS without libraries? I guess not, but that's a MTA's policy. Yes SDK really outdated. MTA don't pay programmers for the refactoring. |
Im working on MTA debugger, you can find this extension in VS Code. |
As a note, that last approval by @ERAGON007 was a mistake 😅 |
This draft pull request is stale because it has been open for at least 90 days with no activity. Please continue on your draft pull request or it will be closed in 30 days automatically. |
This draft pull request was closed because it has been marked stale for 30 days with no activity. |
Today there was a discussion on dev discord, that i think is valuable for putting a few things into perspective, should CrosRoad95's large PR's like this & Bullet Physics (BP) engine turn out to not get merged. I can very well relate to devs that are hestitant, and dont want to, as they say, burn their fingers on it The discussion: https://imgur.com/a/seD0hqQ |
Admision:
The goal of this project is to add javascript programming language to mta sa, lua going to be untoutched. Everything what will used by both lua and js will turn into generic class to support both or more languages. I want as much as possible avoid duplication of current.
General idea
text, rect ( two vector2 ), style object
.Typescript
Yes, it will compatible with typescript. If possible i would like to make mta compilation to generate typescript definition as well or generate them in different way using source code.
Initial pull request
This pull request will implement only two classes "crypt" and "utils", related features, promisses, new parser support ( same as lua ) Vector2/3/4 Matrix, Color, classes. Nothing more, just simple working version of javascript.function "print" to print things, "version" to see a current version of v8. Nothing else
V8
Because of fakt that compiling javascript is not trivial task i decided to use precompiled libraries for each platform with debug symbols as a part of this project along with instructions, configuration i used to compile it.
It is possible to download precompiled from google server: https://storage.googleapis.com/chromium-v8/official/canary/v8-win32-rel-8.9.276.zip but they are shipped with flag
use_custom_libcxx
set to true. It may work but it adds extra layer of complexity to mta project itself ( eg. forces to use https://releases.llvm.org/ ).Current version of v8 is: 8.9.255.20 ( week, two ago it was last stable based on https://omahaproxy.appspot.com/ ), same version is used currently by chrome browser ( check your version at: chrome://version/ )
Project assumptions
To communicate with v8 library i created shared project "MtaV8". Goal of this project is to implement exact same logic for client and server. Client Deathmatch and Deathmatch ( server side ) are using interface to communicate.
Functions and more what can be accessed from js will declared in previously mentioned projects.
Style of programming ( mostly function names, arguments ) will simillar to lua, but i'm taking better examples of solving problems from node.js, chrome browser.
Test project
In newly created folder "tests" i put test console project
v8tests
copy pasted from https://github.com/v8/v8/blob/master/samples/shell.ccJIT
Supported and enabled. If function is "hot and stable" it will optimized and recompiled. That functions are almost as fast as c++. There is a feature to trace what function are JITt'ed ( leaved for future update ).
Performance
Only raw runtime will benefit, loop without usage of mta api will execute much much faster than lua.
New configuration options in mtaserver.conf ( Moved into future update )
Future:
Webassembly
Disabled right now, may be added in future updates :) .
Multithreading
Yes, but per resource. Topic for future update. But if you use "await passwordHash(...)" it will computed on background thread.
I also did an investigation and each resource / javascript isolate can run parallel.
It is possible to make resource with exported heavy functions such a path finding and use
await someResource.findWay(...)
Exports
I did not tested it, but i'm almost 100% sure you can export/import everything ( including functions, objects ect ) across resources. Topic for future update. Client server commucation will support only primitive types.
Communication with lua
Possible as well, for future update. I though about form where you can import lua files as a regular javascript module
import { context from "foo.lua"
and use methods, properties over "context" to set/get/call lua functions.Todo:
If anyone have a suggestion, question, ask.
Test resource:
js.zip