-
Notifications
You must be signed in to change notification settings - Fork 196
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
Replace LuaJ with Cobalt #163
base: master
Are you sure you want to change the base?
Conversation
This would also make it easier to distribute CC, and make it easier for other developers to compile against CC. With cobalt properly registered as a Gradle dependency, you no longer need a set of scripts to deploy and instead can compile a fully functional version of CC with just |
Since this is quite a monster of a PR, I think it's worth emphasising that Cobalt has been tested in battle quite extensively before, so merging immature code should not be a concern here. Notably, SwitchCraft, when it was still active, had this fork in use via CCTweaks, which allowed it to stabilise significantly. |
All I can say is 🎉 👍 ✨ 👏 📦 👌 🍷 🔁, please merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove luaj distribution in repo
@jamierocks I've deliberately avoided that in order to reduce noise and make it clear what changes this PR makes. It should be trivial to delete the LuaJ sources at a later date. I've removed the code which will package LuaJ, so at least it's not shipping two Lua versions 😄. |
@SquidDev I'd still say remove it tbh. Either way at least remove libs/luaj.*.jar |
(I know this is not the best place to mention it but) have you considered looking into merging your fixes into LuaJ itself? would befit more than just the CC community. |
+1. How much code will this break? |
If I've done my job correctly, none. Several servers use Cobalt already, and haven't experienced any issues. It is a fork of LuaJ, and so shares most of its functionality.
I haven't really thought about it. AFAIK LuaJ 2 (the version CC uses) is no longer developed. Many of the changes also break binary compatibility - hence the change in package name. I'd love for Cobalt to be merged into LuaJ, I just don't think it is feasible given some of the changes made. |
Nice! That is very good. Will any java code break, or are the changes easily fixable? |
No code using the public API should break ( |
That's cool. +1, definitely merge this |
@dan200 I realise there are other PRs out there which are objectively more important than this one, but I was wondering if you have any thoughts on this PR? I realise this is a massive change so isn't going to be an instant merge (or a merge at all for that matter), but I would be interested to know your thoughts. |
Not trying to rush things, but it would be really nice to see some feedback on this @dan200. It would be a great change and fix a lot of headache with LuaJ, and open up a lot of new possibilities for features. |
fb51233
to
b8b0496
Compare
If you're planning to change the Lua engine, why not use LuaJIT directly? It's extremely fast and supports most architectures. |
@JustPingo Cobalt is pretty much LuaJ with some bug fixes and minor improvements, meaning it isn't as dramatic a change as swapping to an alternative Lua runtime (such as LuaJIT or PUC Lua). On the subject of LuaJIT itself, I can see a couple of potential issues:
I have got a WIP Lua to Java JIT which, if I could optimise it a little more, could be worth looking into. When Java 9 ships, one could also look into writing a Graal/Truffle Lua implementation. I might be over complicating this a little though 😄. |
What kind of broken functionality are we dependent on? If its a small thing it might make sense to drop it? |
@Wojbie The thing which first springs to mind is that One thing worth noting is that using a Java implementation of Lua means we can execute bytecode without a security risk - allowing for programs like JVML-JIT and LuaLua. Sure, this is a small price to pay, but it would be a shame to lose this sort of functionality. |
I don't understand the theoretical risks of using Lua outside of the JVM. OpenComputers does it and disables bytecode as well. Why? I understand some exploit could end up with memory corruption, but couldn't that just happen in Java as well? Now I totally agree with replacing LuaJ with Cobalt. |
Yes. It's more about how ComputerCraft currently interacts with coroutines and expects them to behave. Methods like I agree that the none of these points are major, but I do still think they are worth bearing in mind. They aren't deterring factors, but should be considered if Dan chooses to use LuaJIT. The broken behaviour relating to I also maintain that using LuaJIT is a totally separate issue - this is just minor modifications to LuaJ, LuaJIT would require a rewrite of much of ComputerCraft's internals. |
Please merge |
c4a66d4
to
5e719a0
Compare
5e719a0
to
c55d431
Compare
Hate me for reviving this, but why is this stagnant...? I would've assumed this'd be the first PR to get into CC, but it's still sitting here open. Like is there some hitch with this? It doesn't even seem like a dual-edge sword, like most PR's that stay open for as long as this one are... |
I've just finished doing a tiny bit of work on Cobalt with some optimising and bug fixing. As I'm preparing for a release, I'm wondering whether it would be better to reference Cobalt as a git submodule instead of a maven artifact. If Cobalt were a submodule, one wouldn't have to depend on an external maven server. Whilst Bintray provides one for free, it may be something we want to avoid. Submodules also simplify updating, as one doesn't need to bother with the whole "bump version, upload, update dependents" faff. However, there is a downside of this: git submodules. These introduce all sorts of additional complications with cloning and pulling which we may want to avoid. I'd really appreciate other people's thoughts on the matter - I'm not sure what the best course of action here is. |
Most IDEs nowadays handle submodules very well, including auto-updating them on pull and pushing changes to them (if changes are done). |
You could just copy the source to the CC repo directly, rather than a submodule, akin to how LuaJ is currently set up, but using a submodule or maven artifact would be much better. |
I don't really see a problem with making Cobalt a submodule. How does it complicate pulling and cloning? Sorry if it's obvious to others, I don't frequently work with submodules myself. I presume that you only need to use a specific command when updating them, however. |
@viluon There's lots of small things, like having to use |
Frankly, I see little benefit to using a submodule. ComputerCraft, will always want to be using release code - little bugs, more accountability (I see people update submodules all the time carelessly). |
@jamierocks the submodule can track a release branch, and frankly, tracking @SquidDev can't you clone the submodule on build? |
@viluon clearly, I need to stop posting late at night - I did not articulate my point very well at all. I was trying to get across that it would put more emphasis on ComputerCraft devs to know what is going on with Cobalt development - which would possibly result in Cobalt not getting updated. (this could be because not sure which releases/commits are going to break CC - appropriately versioned dep releases doesn't have this problem, although there quick fixes can't be merged quickly) My other point, was that tracking a specific version is just a much more painful method than using a Maven dependency (having to recursively clone, etc) - the two get the exact same result, the easiest option IMO would be the desired one. I totally see your point with using a branching model (that has a 'stable' branch), however in that case, Cobalt would have to make alterations - for something which can already be accomplished (through Maven dep). Basically submodules are only useful if you know exactly what development is going on upstream. If you are tracking specific releases, you are just making life harder - having to combine the build scripts of Cobalt into CC, etc. Don't get me wrong - I love submodules, however from my use of them, I have found that Maven dependencies (when they can be used) are far more appropriate - especially when you'd have to combine two builds. (although at least both use Gradle here) |
The string metatable and environment are no longer shared, so this sandboxing is no longer required.
This means loops which do not touch CC specific methods will still produce an error, rather than terminating the computer.
Whilst this is not consistent with normal Lua, this is required in order to remain compatible with LuaJ.
c55d431
to
0bd0f4d
Compare
It's been a year, so I thought it would be a good time to mention that we've been running this on several relatively popular CC-based servers for a while now, and not experienced any issues. I can't comment on the benefits it has brought, as they're all relatively subtle and so one doesn't tend to notice it. That being said, there's been many times the additional information provided in errors has come in useful, as have the improvements to yield protection. Several servers have also been running with Cobalt's Anyway, happy birthday to ComputerCraft being open sourced 🍰. Here's to year 2 🍻. Thank you to everyone who has contributed! |
- Default to using little endian in string.dump - Remove propagation of debug hooks to child coroutines - Use [C] instead of function name in traceback. - Various improvements to string formatting:
…cobalt Replace LuaJ with Cobalt
I realise this is a bit of a long shot as it fails the first criteria, but I do still think this is worth considering.
Cobalt is a fork of LuaJ I started a long time ago to address a couple of bugs (#91, #97) in LuaJ. It's kinda expanded a bit since then, with the following improvements:
pront()
would give youattempt to call global 'pront' (a nil value)
instead,loadstring
doesn't include the caller, etc...).However, this is nowhere near as used as LuaJ, so there may be some unknown issues. There is also no Lua 5.2/5.3 version, which may disrupt your future plans.
Synopsis changes in this PR
LuaJMachine
withCobaltMachine
while true do end
. With the new system, you will get an error mid iteration. It should also fire errors when in very long pattern matches.Potential improvements
debug
API into the environment. Thedebug
API is immensely useful, so would be nice to have. However, there may be some way I am unaware of to abuse it - even if you cannot leak into other computers any more.require
and thepackage
library. Cobalt adds the ability to use custom filesystem providers, so it should be possible to addrequire
without breaking the sandbox.os
library - As mentioned above, Cobalt allows custom filesystem providers, meaningos.rename
andos.remove
can be implemented in a sandbox friendly manner.Potential issues
Note: I haven't deleted any of the LuaJ sources in this PR, as to keep it readable. That will need to be done in a later commit.