A live coding environment for large Codea projects.
xCodea lets you seamlessly switch working on your Codea project from your iPad to your laptop/desktop (and back), to take advantage of
And most importantly:
Assuming your computer's IP is 192.168.1.10, you will keep your projects in a folder named CodeaProjects (this folder is generally referred to as projectsRoot) and you'll work on a Codea project called MyCoolGame:
git clone http://github.com/lowne/xCodea.git CodeaProjects; cd CodeaProjects
- or download the ZIP and extract its contents into CodeaProjectsnano xCodea/EDIT_THIS.lua
- or open EDIT_THIS.lua inside the xCodea subfolder with a text editorxCodea_server = "http://192.168.1.10:49374"
then save./xcodeaserver.py MyCoolGame
(I suggest adding -lcsn
for remote logging, colour output, sound and notifications on errors)Grab the .dmg file from the latest release. Usual caveats apply for Gatekeeper (right-click, open) and firewall (the server requires inbound connections, eh?) It'll ask for your projectsRoot at first launch, type it in. Then Project->New Project->MyCoolGame
, then Start server
.
http://192.168.1.10:49374
in the location bar[ TODO command line options etc]
When xCodea on the iPad connects to the xCodea server any changes (files or dependencies that were updated, added or removed from either side) are synced. In practice almost always you'll have been working on your project on the iPad while away from the computer. When you connect to xCodea it'll sync these changes back to the computer. In case of changes from both sides on the same file, the iPad version wins by default, overwriting the file on your computer.
--push
and --pull
options on the server [ TODO not yet implemented in the GUI]You can disconnect (stop xCodea, quit Codea altogether, put the iPad to sleep, take the iPad on a long trip) whenever you want; the next time xCodea connects it'll sync any intervening changes and restart the project. There's no need to ever stop and restart the server unless you want to work on a different project (to stop the command line server, press ctrl-C in its terminal window).
Whenever a project file is changed on disk (i.e. on save) its contents are sent to the client.
Moreover the server watches for a special eval.luac
file in your projectsRoot folder. As soon as this file is created, the server sends its contents to be evaluated inside xCodea's sandbox, then deletes the file.
xCodea.restart()
to safely reset the sandbox and restart the project executionFinally, if you're using LDT (or some other Eclipse-based IDE) xCodea monitors the .buildpath
file for your project to detect dependency changes (when a change occurs the project is automatically restarted).
myClass = myClass or class()
or myObj = myObj or {}
. If you use myClass = class()
myClass will be recreated every time the file is evaluated (which is every time the file is saved), destroying its state. Similarly, you should avoid initialising variables in the main chunk of a file - use setup functions (called in turn by the main setup()
)During execution of a Codea project there is normally a single entry point for your code - the draw()
function. xCodea gives you another entry point: update()
. Take advantage of it to separate program-state updates and actual drawing; this improves a lot feedback during live coding as runtime errors in update()
won't affect drawing.
function update() ... end
somewhere in your project (usually in your Main.lua), and you must call update()
as the first statement inside your draw()
(or any other function in your draw call chain - xCodea should be able to hunt it down and set the hook). Simple example:function update()
-- update the program state here
...
end
function draw()
update()
-- do your drawing here
...
end
tween.update
from your draw loop - e.g. runtime errors in callbacks from tween(..., callback,args)
won't affect the draw loop (but the callback will be terminated)eval.luac
for a REPL-like experience. For example I use BetterTouchTool to intercept some key combinations while in LDT:
pbpaste > path/to/projectsRoot/eval.luac
(eval the current selection)echo "xCodea.restart()" > path/to/projectsRoot/eval.luac
(restart the project)eval.luac
, xCodea will do the required print()
wrapping (and sending to the server log) for you.xCodea was inspired by, and strives to improve upon, the excellent LiveCodea, which begot AirCode in Codea itself, whose limitations xCodea attempts to overcome. Some ideas were taken from the also excellent AirCodea