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
Luau #2815
base: master
Are you sure you want to change the base?
Luau #2815
Conversation
One thing from my side: if possible, download vendor files from luau repository to do not bloat mta codebase and make future updates easier, |
Unfortunately, we cannot use the default Luau code in the future. Some adjustments required in the code. |
you can download luau and make a folder with patched files you copy onto luau files This pr just show how much the mta team doesn't give a damn about this project |
Instead of < lua > could be better to set lua version per script. |
This goes against the current implementation whereby each resource has its own Lua VM (on client and server) |
Disagree, if you have a need to mix Lua versions you should split it up in multiple resources. |
Thanks |
IMHO pros and cons: Pros:
Cons:
My opinion - lgtm. |
Not finished, but already usable |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This.
I guess there are nightlies, but even for that the PR has to be tested (and be somewhat stable). So anyways, let's get the ball rolling.I'd like this to be merged, unlike my attempt at LuaJIT (Also, Luau is better maintained, so it's superior anyways). On another note...Before we do all of that, we need some netcode stuff too for checking if luau scripts are signed, until then compiled scripts are a no-go, executing untrusted bytecode is dangerous (Same reason why currently Lua scripts go thru MTA's site, they get signed too) |
This is the reason for the excessive memory usage of Luau. Luau doesn't has LUAI_EXTRASPACE feature so I was forced to implement it on my own by allocating an extra 4 bytes for every memory page. And this must be removed in future by commiting to the Luau project directly. |
That is the answer to my problem, thanks. Also, is this |
No, 0x5989C266 is the completely custom invention. It just a way to differentiate Luau and Lua 5.1 by having just a pointer to a Lua state. |
Okay, so we ended up deciding that adding an extra |
Update: Adding anything before the header probably won't work. I tried adding LUA_EXTRASPACE to |
Okay, I give up.
I'd honestly go with 2. Main reason is performance and a memory usage - Merging something that could drastically increase memory usage could harm servers that are already on the edge of that 4GB limit. I think higher performance+less memory usage would be totally acceptable for the cost of having to recompile your scripts. |
From my standpoint option 2 is the best. As you said, if the scripts were obtained legally it's easy enough to re-compile them, not a big deal. The pros outweigh the cons in this scenario. |
Same, 2. option is the best. Just the new features (continue statement, compound assignments, etc..) alone could help a lot writing better codes. This is a no brainer in my opinion, if it’s possible. |
Why do we need a translation layer if we ship both Luau and Lua 5.1 and use the respective VM depending on the resource setting? In both cases only one VM would be running and Lua(u)-objects would never hit another VM. 2 is not a realistic option. There are too many compiled scripts out there that'd just break, where source isn't available because no one ever cared about it. At that point we'd just be creating another MTA fork.
Those should move to x64 anyway. |
A line has to be drawn somewhere for the sake of progression. We just can't keep hindering ourselves to maintain backwards compatibility for outdated scripts that are more likely to be insecure (and with the source lost you can't even verify it) anyways. We need to force the community to improve and ensure MTA does so right alongside them. |
Not really. Many people update their servers that have no idea how to do anything in Lua. Also this would break client scripts as well, for example in various race maps.
Yes. However the benefit of breaking compatibility also needs to be weighted against the downsides of it. I don't consider Luau to be that significant of an upgrade over standard Lua for it to be worht breaking all existing compiled scripts.
|
Regarding compiled scripts (from race maps or whatever), if mta team would provide a fast batch decompiler of luac to get the readable pseudocode back and potentially recompile it for luau, then this could work. |
GTA is still 32bit, and will be until we finish reversing it. So x64 won't help.
Because we need to know which New: Option 5We would increment the version to 1.7, this way everybody gets to keep MTA with Lua 5.1. Server owners with compiled scripts without sources would be stuck on the last 1.6 version, and everybody else would be on 1.7 enjoying Luau (And let's be real, majority of players play on servers that will be able to move to 1.7). Also, server owners not having sources and not know much about Lua wouldn't have much use anyways of newer versions - They can't take advantage of new features, if they don't know how to script in Lua, no? |
VM selection on resource start is the best(from the perfromance perspective) solution. But how does this can be implemented? if-else statements for every lua function call site? The strategy pattern? It will require a lot of refactoring. And that is the reason why the translation layer system was chosen. It requires almost no modification of the existing MTA codebase, works as fast as possible and can be easily extended. |
I didn't review this PR deeply enough to know if I'm about to say something impractical, but why can't we just default to Lua 5.1 for resources that don't explicitly opt-in to Luau in the If we ship both Lua VMs, and only create the appropriate one after parsing the |
In this PR the only one VM exists at the same time for each resource. And Lua 5.1 is already default. Without the virtualization we simply won't be able so dispatch the Lua function calls. |
Right, I understand this overhead is needed because we want to instance the same, multi-version VM across resources. But what is preventing us from using different VMs for different Lua versions for different resources? |
It seems that this PR and its implementation details are unclear for most of the people. It adds a custom translation layer (called vlua) that replaces Lua API functions by its own "proxy" versions. So, lets say MTA is calling lua_pushstring, which is actually a vlua function that internally deduces the version of Lua from a lua_State pointer. And then using that information it invokes the corresponding Lua function which can be Lua 5.1 or Luau. Currently the Lua version is deduced by a special "magic" field that's placed before the lua_State object. Simple, fast, scalable. |
Thanks @tederis, that explanation made it much clearer to me! I think it's a fundamentally smart approach. |
Some if-else and a bunch of templates. It's a bit more work, but it doesn't sound too bad. I would've reimplemented the Lua API as That way we can avoid any runtime CPU overhead and only gain some code size. |
They can install resources with new features without Lua knowledge. It's allowed to use EmmyLua with MTA to have all benefits of typed language. Or you can use TypeScript -> Lua transaction layer and have significantly better language that Luau. This options request no changes in MTA codebase. Lua community provides a lot of native modules for Lua. LuaRock is partially integrated in MTA and provide some multi-threading support for windows. There is also a lot of ways to use Lua knowledge. Defold uses Lua as main language. Project Zomboid, Garrys Mod, BG3 SE use Lua for mods I am not a fan of this changes. EmmyLua + debugger provide the best Lua developing experience for me. Maybe somebody is going to add Luau in MTA. Just please, don't break old resources. Luau has not enough benefits for it. |
It's just the way MTA works.
Lua is slow. Luau is faster. LuaJIT is the fastest, but security is questionable (The main reason why Luau isn't JIT). |
For what it's worth, I think the approach outlined by @sbx320 seems worth exploring to move this PR closer to being merged, in addition to moving Luau to a submodule whose changes can be easily tracked under version control. I find that @TheNormalnij has some valid points about Luau's addition not being strictly necessary to MTA, but given that:
I think realistically there is no downside to this PR, so I would recommend against letting this good effort go to waste. I would indeed advocate for caution in adding big features like Bulletphysics, because those are either complex in themselves or open cans of worms in terms of future complexity, practical usability in their MVP form, expansion, and maintainability, but this kind of "infrastructure" improvements pack, in my opinion, a lot of bang for the buck that's worth the relatively little effort. |
Also, something LuaJIT, and Lua 5.1 doesn't have is native vectors, that cause no GC pressure. |
Sometimes we do very small changes in API. This changes doesn't breaks much and old resources can be adopted. This is ok for me. Lua is a very sensitive part of MTA. And changes in bytecode break a lot of old resources. There is a lot of script markets, where server owners buy compiled scripts. Some freelancers sell compiled resources only. I think we are going to break too many things.
In my experience Lua is fast enough. MTA performance is suffering from bad decisions in API + Bad API
#1728 we can change our Lua implementation and do event better for MTA. |
Keep Lua as it is, add Luau (optional) that can be enabled in meta.xml |
Others have said before that if we keep 5.1, it would need a translation layer, causing more cpu usage and it would use more memory, I don't think it's an option, performance isn't that good currently either, and it would be even worse if we keep 5.1. If we keep worrying about backwards compatibility, the game will never get a decent upgrade, I don't see why the game has to support 15 years old compiled (mostly stolen) scripts. 99.9% of the time if you are a server owner/developer, you wouldn't backup just the compiled scripts, you would backup the sources too, only if you didn't steal it from other servers of course.. |
I think we are talking about two parallel version without big performance impact. Transaction layer is too hard |
I don't understand what you are saying, there would be a pretty big performance hit if we keep both languages, Pirulax said it already.
Also the translation layer is literally the chosen method in this pr, it's already working, so I don't get what you are trying to say. |
Ah, i forgot this information, sorry |
This is an attempt to add a new Lua version along with the default one. In this PR you can find an implementation of an interface allows to switch between Lua 5.1 and Luau in runtime. Can be considered as stable but due to the complexity can potentially contain issues that are expected to be revealed after the release.
lua5.1 and luau libraries are shared now for all build configurations. But Lua_Server and Lua_Client are static. It makes the system flexible on the one hand and resolves the name conflict on the other.
You can enable Luau for a specific resource for client, server or both.
Due to the flexibility of the interface new versions of Lua can be added in the future.