This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
awsmazinggenius's profile picture

Would anyone be interested in a CC Emulator made in Python?

Started by awsmazinggenius, 09 January 2014 - 07:15 PM
awsmazinggenius #1
Posted 09 January 2014 - 08:15 PM
I am sure you all are well aware of the fact that there is no currently widely used ComputerCraft emulator. CCEmu is long abandoned, Lochie has "taken a break" from ComputerCraft, including CCDesk, I haven't seen Gravity's CC Emulator at all yet, and Sorroko's CCLite is definitely lacking some of the features the above emulators above (No offense to Sorroko at all - it actually is a really great emulator, but it could use some more features.) Well, I have not used Python (real Python, not 5-minutes-to-make MCEdit Filters) in quite a while (well before Python 3 came out) and would like to relearn the language (not silly things like "Hello World", though I guess they did change print to a function), and I would like to do so by making a few projects, including a possible CC Emulator. I would like to say, right now, that I am not making a guarantee that I will make the emulator, and if I do (likely), it will take some time to relearn the language, and then to code the emulator. However, I made this thread to see a) who/how many people would use the emulator, and B)/>/> to get some ideas from the community. When I am done making the emulator, I'd probably also want to run it past Dan to see if it's OK to release and open-source it, even though I did use my own code. (Just to be safe, because even if it is my code, CC was his idea.)

Things I already came up with that I want to code into the emulator
  • Full Redstone support, including bundles cables. I plan on doing this by having a window that you can open that displays the colors (or just the fact that redstone is on for normal redstone) that are currently enabled. This will probably require that I increase my skill with RedPower 2/MFR.
  • Rednet/Modem support. Not sure how to go about this, should each computer have a virtual "position", or should every message be reachable by every computer?
  • Peripheral support, for the vanilla peripherals. I don't plan on doing support for peripheral mods, simply because I don't know how I should do it without requiring that the peripherals be rewritten for Python. If you have a good way to do this, be my guest.
  • Exportable computers, where you can export a computer to a .ccpy-computer (extension likely to change) file, saving it's files, it's term size, it's label, everything, to a file that can be emailed or something to a friend, who can then open the file and get the exact same computer
If you have an idea that isn't on the list, fire away! Also, I need a name for the emulator. The only one I can think of is ccpy, but if you think you have a better one, post it! I will credit for ideas and names I use.
Csstform #2
Posted 09 January 2014 - 10:14 PM
I would use it if it worked through the python android app.
awsmazinggenius #3
Posted 09 January 2014 - 10:26 PM
I have a feeling it might not due to external libraries I plan on using, but you could try. Also, it's a whole window (like CCEmu) with all your functions. Are you using an Android tablet, or a phone? If you're using a phone (most likely), won't the screen be a bit small?
Symmetryc #4
Posted 09 January 2014 - 10:34 PM
You forgot gamx92's Emu (forked from Sorroko).
Csstform #5
Posted 09 January 2014 - 11:32 PM
Tablet, and I have an external keyboard for it. I'll at least try it.
awsmazinggenius #6
Posted 10 January 2014 - 02:27 AM
Hmm, I'll look into gamax92's emulator. And, Csstform, if you have a tablet with an external keyboard then it might work for you, it all depends on how the wxPython (subject to change to another method) library works for you.
Edited on 10 January 2014 - 01:27 AM
oeed #7
Posted 10 January 2014 - 04:06 AM
If it was worked well, yes I'd use it.

After talking to GravityScore yesterday about his emulator I do believe he's working on a public version.

But at the end of the day, if it works well and supports Mac I'll consider using it. Also, if possible try to make so it doesn't use masses of power. If I'm running Minecraft or CCEmu my battery only goes for about an hour and a half. Using Mimic (GravityScore's emulator) I get over 5 hours and my Mac doesn't get hot enough to cook something either which is a bonus when your working in 40+ ˚C heat (that's 100 ˚F+ for you Americans). To achieve this I personally wouldn't use a standard graphics library that draws the screen as often as possible. I'd only draw when a pixel changes which shouldn't be too hard. But I've never use Python or looked at making an emulator, so I could be wrong.

Oh, and I'd also try to make sure it's easy to switch versions (using the .zip) so you don't have to constantly update it.
Bomb Bloke #8
Posted 10 January 2014 - 04:27 AM
There's also shiryavsky's CCTurtle emulator. Can't say I've played with ANY of them myself.

I usually use repl.it if I want to quickly test some code.
Edited on 10 January 2014 - 03:28 AM
oeed #9
Posted 10 January 2014 - 05:24 AM
I usually use repl.it if I want to quickly test some code.

But, it doesn't have the CC APIs???

It does show that a JavaScript based emulator is probably possible though.

Edit: Does anyone know if it's running server side or client side? All the code's been minified and is rather hard to decipher.

Edit 2: Well turns out someone made a Lua VM for JS. http://oxyc.github.io/luaparse/examples/treeview.html Food for thought if you haven't done much Python recent. If you don't do it I'll consider it when I eventually finish OneOS (which is going to be some time yet by the looks of it)
Edited on 10 January 2014 - 04:32 AM
M4sh3dP0t4t03 #10
Posted 10 January 2014 - 07:46 AM
If you do this I'd suggest using Kivy for the GUI, because it supports Mac, Windows, Linux, iOS and Android.
6677 #11
Posted 10 January 2014 - 11:13 AM
Is there even a lua VM for python? I wouldnt have thought there is any market for such a thing considering python can simply load external python scripts if scripting is necessary.
awsmazinggenius #12
Posted 10 January 2014 - 11:55 AM
That is a good thought, requiring a Lua VM. I thought I could just try and parse all the commands, but that is really silly of me. I'll look around.
6677 #13
Posted 10 January 2014 - 01:26 PM
https://pypi.python.org/pypi/lupa/0.9
Seems your best bet.

(in relation to the below: none of the lua bindings for python I have found so far work on android)
Edited on 10 January 2014 - 01:27 PM
CoLDarkness #14
Posted 10 January 2014 - 02:17 PM
I'd like it if it works on phones and it has quality.
oeed #15
Posted 10 January 2014 - 05:09 PM
I don't this phone support would work really, the screens too small unless you had an external keyboard. Tablets would probably work as long as you position it out of the way of the keyboards.
Kingdaro #16
Posted 10 January 2014 - 06:12 PM
You could overlay a transparent keyboard over the computer screen, like how some games overlay gamepad-like controls over the screen during gameplay.
oeed #17
Posted 10 January 2014 - 06:49 PM
You could overlay a transparent keyboard over the computer screen, like how some games overlay gamepad-like controls over the screen during gameplay.

I suppose, but you'd need to have a button to hide close it. Is it really necessary to have a CC emulator on your phone anyway. When would you use it?
CoLDarkness #18
Posted 11 January 2014 - 08:45 AM
You could overlay a transparent keyboard over the computer screen, like how some games overlay gamepad-like controls over the screen during gameplay.

I suppose, but you'd need to have a button to hide close it. Is it really necessary to have a CC emulator on your phone anyway. When would you use it?

It'd be handy in school and such where I am overly bored.
awsmazinggenius #19
Posted 11 January 2014 - 12:52 PM
I'm looking into making the emulator, and I have started messing around with Python. I'm wondering, is the Android app you are talking about use C-Python or Jython? If it uses Jython, then it might have some weird bugs, just as LuaJ has som weird bugs compared to C-Lua.
6677 #20
Posted 11 January 2014 - 03:07 PM
I'm looking into making the emulator, and I have started messing around with Python. I'm wondering, is the Android app you are talking about use C-Python or Jython? If it uses Jython, then it might have some weird bugs, just as LuaJ has som weird bugs compared to C-Lua.
Jython doesnt function under dalvik (android is not java as commonly stated, it only uses java source files).

QPython appears to be the only real functioning app for python on android. Its python 2 not python 3 and includes kivy, it achieves this through CPython running through the android NDK rather than using the dalvik virtual machine. Lupa doesnt appear to function under it though so you might have to write your own lua interpreter in python.
Kingdaro #21
Posted 11 January 2014 - 04:01 PM
I suppose, but you'd need to have a button to hide close it. Is it really necessary to have a CC emulator on your phone anyway. When would you use it?
It would essentially be a mobile CC emulator for people who don't own a tablet.
awsmazinggenius #22
Posted 11 January 2014 - 04:11 PM
If it is Python 2, is is very unlikely that it will be supported. I am writing this in Python 3, and I have no plans to port to Python 2.
oeed #23
Posted 11 January 2014 - 04:28 PM
If Andriod doesn't support Python why not write it in C or another language that is supported?
awsmazinggenius #24
Posted 11 January 2014 - 05:40 PM
oeed, I don't think you get my point. I want to relearn Python, and this would be a project I do while I'm learning. Someday I might port it to Android, but I'm not keen on buying a Apple App Store developer license (although I prefer iOS to android), so somebody else can deal with that.
6677 #25
Posted 11 January 2014 - 05:51 PM
Personally I think a computercraft android app would have to be specifically written for android rather than having a cross platform affair. The interfaces and technologies are too different for a cross platform application to work.

Stick with PC. Although again, I think lupa might be Python 2 only (not too hard to hop between the 2 versions)
awsmazinggenius #26
Posted 11 January 2014 - 06:14 PM
Nope, it has Python 3 support.
Advantages over LunaticPython
  • separate Lua runtime states through a LuaRuntime class
  • Python compatible wrapper for Lua coroutines
  • proper encoding and decoding of strings (configurable, UTF-8 by default)
  • frees the GIL and supports threading in separate runtimes when calling into Lua
  • supports Python 2.x and 3.x, potentially starting with Python 2.3 (currently untested)
  • written for LuaJIT2, as opposed to the Lua interpreter (tested with LuaJIT 2.0.0-beta4)
  • much easier to hack on and extend as it is written in Cython, not C
[indent=1]
[/indent]

I may, someday, write an Android CC emulator, but since I'm not a fan of Obj-C, someone else can do iOS.
oeed #27
Posted 11 January 2014 - 06:47 PM
oeed, I don't think you get my point. I want to relearn Python, and this would be a project I do while I'm learning. Someday I might port it to Android, but I'm not keen on buying a Apple App Store developer license (although I prefer iOS to android), so somebody else can deal with that.
Ohhhh, I get it now :P/>

Nope, it has Python 3 support.
Advantages over LunaticPython
  • separate Lua runtime states through a LuaRuntime class
  • Python compatible wrapper for Lua coroutines
  • proper encoding and decoding of strings (configurable, UTF-8 by default)
  • frees the GIL and supports threading in separate runtimes when calling into Lua
  • supports Python 2.x and 3.x, potentially starting with Python 2.3 (currently untested)
  • written for LuaJIT2, as opposed to the Lua interpreter (tested with LuaJIT 2.0.0-beta4)
  • much easier to hack on and extend as it is written in Cython, not C
[indent=1]
[/indent]

I may, someday, write an Android CC emulator, but since I'm not a fan of Obj-C, someone else can do iOS.

To be honest, I probably wouldn't even bother with an iOS emulator. You wouldn't be able to use the .jar (or .zip in the newer versions) so you'd need to essentially rewrite the entire mod.
Edited on 11 January 2014 - 05:48 PM
M4sh3dP0t4t03 #28
Posted 12 January 2014 - 03:51 AM
To be honest, I probably wouldn't even bother with an iOS emulator. You wouldn't be able to use the .jar (or .zip in the newer versions) so you'd need to essentially rewrite the entire mod.
Is it possible to use .jar files on android? Android just compiles java source files to its own bytecode, but as far as I know it can't run Java bytecode.
theoriginalbit #29
Posted 12 January 2014 - 04:21 AM
To be honest, I probably wouldn't even bother with an iOS emulator. You wouldn't be able to use the .jar (or .zip in the newer versions) so you'd need to essentially rewrite the entire mod.
Is it possible to use .jar files on android? Android just compiles java source files to its own bytecode, but as far as I know it can't run Java bytecode.
Of course its possible, with both languages, there's normally ways to run one language's source and bytecode in another, normally it just requires some kind of interpreter library.
Also to that point GravityScore's emulator, Mimic, is written in C++ and runs and interfaces with the ComputerCraft jar. This means he could really put in on anything he wants, 'cause both iOS and Android support development in C++ its normally the language that developers use to make games for those platforms…
oeed #30
Posted 12 January 2014 - 04:38 AM
Also to that point GravityScore's emulator, Mimic, is written in C++ and runs and interfaces with the ComputerCraft jar. This means he could really put in on anything he wants, 'cause both iOS and Android support development in C++ its normally the language that developers use to make games for those platforms…

I hadn't actually thought about that, but I'd presume you'd still need Java installed wouldn't you?
theoriginalbit #31
Posted 12 January 2014 - 04:41 AM
I hadn't actually thought about that, but I'd presume you'd still need Java installed wouldn't you?
Surely someone's made some kind of portable JVM with a library. I'm sure this isn't the first time that someone wants to use jar as a resource in Objective-C.
6677 #32
Posted 12 January 2014 - 05:11 AM
.jar files are .zip files, I presume these emulators are only actually after the ROM folder so they just need to open the jar as a zip and read normal plain text, no JVM required
theoriginalbit #33
Posted 12 January 2014 - 05:52 AM
.jar files are .zip files, I presume these emulators are only actually after the ROM folder so they just need to open the jar as a zip and read normal plain text, no JVM required
yes jars are zip files. but they're also contain compiled code, so reading plaintext not so much.
Edited on 12 January 2014 - 04:52 AM
6677 #34
Posted 12 January 2014 - 06:52 AM
.jar files are .zip files, I presume these emulators are only actually after the ROM folder so they just need to open the jar as a zip and read normal plain text, no JVM required
yes jars are zip files. but they're also contain compiled code, so reading plaintext not so much.
The emulators are after the rom folder which is stored in plain text, this is easily confirmed by you know… opening the zip file for yourself…

The lua files are compiled as resources, aka copy and pasted in their original form, the java compiler does not alter them in any way. Nothing else in there is needed to emulate computercrafts environment.
Edited on 12 January 2014 - 05:53 AM
theoriginalbit #35
Posted 12 January 2014 - 07:03 AM
The emulators are after the rom folder which is stored in plain text, this is easily confirmed by you know… opening the zip file for yourself…

The lua files are compiled as resources, aka copy and pasted in their original form, the java compiler does not alter them in any way. Nothing else in there is needed to emulate computercrafts environment.
not all the emulators are after the rom files. actually on second thought, it would be a stupid idea to make an emulator only using the rom folder. to truly make use of the ComputerCraft environment you'd want LuaJ which is the Lua implementation for Java, you'd also want all the other little hacks and APIs that are in the mod Java-side. these are the parts that require having a JVM, all the stuff in the rom folder is trivial, just little apis and such that have been put together to make our lives as developers easier, all the "heavy lifting" and real work is done in the Java classes.
Edited on 12 January 2014 - 06:03 AM
M4sh3dP0t4t03 #36
Posted 12 January 2014 - 11:39 AM
Surely someone's made some kind of portable JVM with a library. I'm sure this isn't the first time that someone wants to use jar as a resource in Objective-C.
Sure, but the App Store guidelines do not allow java code to be used.
awsmazinggenius #37
Posted 12 January 2014 - 03:18 PM
Surely someone's made some kind of portable JVM with a library. I'm sure this isn't the first time that someone wants to use jar as a resource in Objective-C.
Sure, but the App Store guidelines do not allow java code to be used.
Link please. After all, I have said, I don't really care for making an emulator for iOS. Someone else can do that should they so desire.

Does anyone know where/if Grav has a thread (link) for his emulator? If he has a nice, working emulator, I might not make mine.
oeed #38
Posted 12 January 2014 - 05:01 PM
[Does anyone know where/if Grav has a thread (link) for his emulator? If he has a nice, working emulator, I might not make mine.

As far as I know, only theoriginalbit and I have it. In a PM he said he's looking at making it public, but I'm not sure if he's actually working on it at the moment.
theoriginalbit #39
Posted 12 January 2014 - 08:01 PM
Sure, but the App Store guidelines do not allow java code to be used.
Link? 'cause I've been part of the Apple developer community for 5 years, and I've never seen that condition.

[Does anyone know where/if Grav has a thread (link) for his emulator? If he has a nice, working emulator, I might not make mine.
As far as I know, only theoriginalbit and I have it. In a PM he said he's looking at making it public, but I'm not sure if he's actually working on it at the moment.
Yeh we're the only ones that have it I believe, but we've got a version that's been deprecated, he's now using SDL2 for cross-platform running. As such he's started again, you can track progress here.
oeed #40
Posted 12 January 2014 - 08:51 PM
Sure, but the App Store guidelines do not allow java code to be used.
Link? 'cause I've been part of the Apple developer community for 5 years, and I've never seen that condition.

[Does anyone know where/if Grav has a thread (link) for his emulator? If he has a nice, working emulator, I might not make mine.
As far as I know, only theoriginalbit and I have it. In a PM he said he's looking at making it public, but I'm not sure if he's actually working on it at the moment.
Yeh we're the only ones that have it I believe, but we've got a version that's been deprecated, he's now using SDL2 for cross-platform running. As such he's started again, you can track progress here.
I think with the Java thing, it's probably more the fact the one's made a Java VM, but I've really got no idea.

Oh so it is on GitHub, I was looking for it a while back but couldn't find it.
Edited on 12 January 2014 - 08:00 PM
theoriginalbit #41
Posted 12 January 2014 - 08:54 PM
Oh so it is on GitHub, I was looking for it a while back but couldn't find it. I'll see if I can figure out how to compile it.
He only made it a few days ago, its not to the point of being able to compile, he's re-writing it.
awsmazinggenius #42
Posted 12 January 2014 - 10:53 PM
I'll see how Gravity's emulator turns out, if I don't like it or I think it needs more features I might release the one I currently have a tiny little bit of code for. If Grav's emulator turns out nice I might not need to release mine.

EDIT: :ph34r:/> Damn ninja
Edited on 12 January 2014 - 09:54 PM
oeed #43
Posted 12 January 2014 - 11:21 PM
Oh so it is on GitHub, I was looking for it a while back but couldn't find it. I'll see if I can figure out how to compile it.
He only made it a few days ago, its not to the point of being able to compile, he's re-writing it.
Oh, I see.

I'll see how Gravity's emulator turns out, if I don't like it or I think it needs more features I might release the one I currently have a tiny little bit of code for. If Grav's emulator turns out nice I might not need to release mine.

EDIT: :ph34r:/> Damn ninja
You're getting ninja'd a lot lately aren't you :P/>
M4sh3dP0t4t03 #44
Posted 13 January 2014 - 07:46 AM
Link please.
Link? 'cause I've been part of the Apple developer community for 5 years, and I've never seen that condition.

From the iOS SDK agreement:
No interpreted code may be downloaded or used in an Application except for code that is interpreted and run by Apple’s Documented APIs and built-in interpreter(s).
Although I guess it still would be possible to compile Java bytecode to ARM code ahead of time.
6677 #45
Posted 13 January 2014 - 01:43 PM
Although I guess it still would be possible to compile Java bytecode to ARM code ahead of time.
That still wouldnt be within apples API's :/

They have been rather lenient on that restriction. Quite a few apps out there are using Xamarin's iOS port of Mono (itself being an open source .NET framework implementation). Mono/.NET and the JVM are very similar technology and should both violate the SDK agreement yet Mono is allowed.

Does the iOS SDK include a lua VM? Angry birds uses lua for example and I dont know if thats something rovio added 3rd party or is part of the iOS SDK. There is also a lua interpreter app for iOS. Speaking of which, android: sigmascript, full lua interpreter on android.
M4sh3dP0t4t03 #46
Posted 13 January 2014 - 03:26 PM
Although I guess it still would be possible to compile Java bytecode to ARM code ahead of time.
That still wouldnt be within apples API's :/

They have been rather lenient on that restriction. Quite a few apps out there are using Xamarin's iOS port of Mono (itself being an open source .NET framework implementation). Mono/.NET and the JVM are very similar technology and should both violate the SDK agreement yet Mono is allowed.

Does the iOS SDK include a lua VM? Angry birds uses lua for example and I dont know if thats something rovio added 3rd party or is part of the iOS SDK. There is also a lua interpreter app for iOS. Speaking of which, android: sigmascript, full lua interpreter on android.
You can call native ARM Code with the API's provided by Apple(Xamarin uses this by compiling the C# code to ARM code). And for the part about Lua: I haven't seen any place where they say that it's allowed, but Apple still let's apps that use it pass(don't ask me why).
6677 #47
Posted 13 January 2014 - 04:29 PM
Although I guess it still would be possible to compile Java bytecode to ARM code ahead of time.
That still wouldnt be within apples API's :/

They have been rather lenient on that restriction. Quite a few apps out there are using Xamarin's iOS port of Mono (itself being an open source .NET framework implementation). Mono/.NET and the JVM are very similar technology and should both violate the SDK agreement yet Mono is allowed.

Does the iOS SDK include a lua VM? Angry birds uses lua for example and I dont know if thats something rovio added 3rd party or is part of the iOS SDK. There is also a lua interpreter app for iOS. Speaking of which, android: sigmascript, full lua interpreter on android.
You can call native ARM Code with the API's provided by Apple(Xamarin uses this by compiling the C# code to ARM code). And for the part about Lua: I haven't seen any place where they say that it's allowed, but Apple still let's apps that use it pass(don't ask me why).
Mono on iOS is running in JIT mode not AoT, so the mono framework itself is actively executing .net bytecode on the device in realtime. Mono AoT is actually quite buggy :/
awsmazinggenius #48
Posted 13 January 2014 - 09:30 PM
oeed: Yes, the amount of ninjas on this forum seem to be increasing.

I'm just wondering; I believe the Lua VM 6677 found uses C-Lua (with LuaJIT.) Should I emulate LuaJ bugs, such as that one with rednet messages being messed up if they were a byte over 128 or something like that?
M4sh3dP0t4t03 #49
Posted 14 January 2014 - 11:39 AM
Mono on iOS is running in JIT mode not AoT, so the mono framework itself is actively executing .net bytecode on the device in realtime. Mono AoT is actually quite buggy :/
Actually it's impossible to use JIT on iOS, because it won't run unsigned code. In the iOS simulator Mono is running in JIT mode, but on an actual device it can't run JIT.