loveCodea - loveCodify revived

Hello gamers and programmers!

I’ve seen Asteroys (, but instead of loading it on to my iPad I thought it may be a good idea to get it running on the desktop.

I’ve taken the loveCodify wrapper, adapted it for LÖVE 0.8.0 and added some functionality until I got Asteroyds running. Like loveCodify, I did enough to get this game running so it isn’t a complete wrapper either. I hope that I can revive interest in it, however.

I’m not a githubber (yet?), so find the new Lua file on pastebin (for one month) and the original luaCodify on github (see file header):

Detailed instructions to get Asteroyds running:

Copy “Asteroyds.spritepack” as “Asteroyds” into the source code directory.

Copy “Tyrian Remastered.spritepack” (extract it from the Codea app) as “Tyrian Remastered” into the source code directory.

Copy “loveCodea.lua” and “vector.lua” (from the original github repo) into the source code directory.

Make a “conf.lua” like this:

function love.conf(t)
    t.title = "Asteroyds" = "Hyro Vitaly Protago"
    t.screen.width = 1024
    t.screen.height = 768

Add this to the top of “Main.lua”:

if require ~= nil then

Run it!

– Stephan

Wow, great work, @Codeslinger. It’s nice to see loveCodea revived like this.

Do you know if Löve has render-to-texture? Similar to Codea’s setContext(). Or an image class? Just wondering if some of the more advanced features are possible in a wrapper.

Thanks! I can’t wait until it’s fully revived…

=== About a render context ===

I’ve seen “Word Spring” ( using an image as a render context. In LÖVE you can use TCFKAF (The Canvas Formerly Known As Framebuffer) and use setCanvas like you do with setContext now.

This could be an image class stub for this kind of use (only showing what Word Spring needs (and I didn’t care about physics yet, so the following lines are not enough to get Word Spring running (and you also need textSize (and I like parentheses, I should be programming in Lisp (yes, I know about Lisping …))))):

image = class()

function image:init(x, y)
    self.c =, y)

function image:get(x, y)
    return self.c:getImageData():getPixel(x, y)

function setContext(img)
    if img ~= nil then

A new version of loveCodea is up on pastebin for one month:

General: No need for vector if there is no need for vector (oh, a tautology, what I mean is that you don’t have to copy vector.lua into the project folder if you don’t need it), name your sprite pack folders with or without a .spritepack extension, and of course many rendering improvements.

Improved running of Asteroyds:

Also tested with Can’t Stop (now it’s official: I’m a board game geek):

Also Towers vs Zombies:

A note about Tower vs Zombies: There is a problem with the gist. I don’t know if it was introduced through github or if juaxix had it really stored this way, but all files contain UTF-8 non-breaking spaces about which LÖVE complains as illegal UTF-8 sequences. You have to first convert them to plain spaces.

Silly me, there’s a bug in function rect(), it must read

y = y - height / 2

instead of

y = y - width / 2

Why am I so keen on telling you this? Well, with an absolutely not serious mini version of a mesh class you can play Backgammon (

mesh = class()

function mesh:new()
    self.vertices = {}
    self.colors = nil

function mesh:setColors(color)
    self.colors = color

function mesh:draw()
    local c = self.colors
    if c ~= nil then, c.g, c.b, c.a)
    local v = self.vertices
    local nvertices = #v
    for i = 1,nvertices,3 do
        local x1, y1 = v[i]:unpack()
        local x2, y2 = v[i + 1]:unpack()
        local x3, y3 = v[i + 2]:unpack()"fill", x1, y1, x2, y2, x3, y3)

Did I say that this mesh is underpowered and only for Backgammon? Good. I’ll try to make a better mesh class. Stay tuned.

NEWS: setContext() deemed impossible … er … difficult

OR: The alas edition.

Löve has a Canvas for off-screen rendering but all matrix transformations so far apply.
Codea has - alas - its coordinate base in the lower left so just before drawing, the Löve coordinate system is transformed. Löve - alas - has no means to load the identity matrix but perhaps this wouldn’t suffice either. Does setContext() observe prior transformations as well? Alas - I don’t have my iPad near me to check this while writing these lines.

The difficult solution would be to remember all Codea calls to matrix transformations and then reset and restore them as needed. Maybe I’ll try it …

Other “difficult” things: Drawing triangle meshes with differently colored edges. Rectangles are OK, the gems in the “Hello Mesh” example render properly.

(Answer to myself)

Checked it on an iPad, setContext() indeed simply sets the drawing context to a different target, still observing the matrix stack that was set until then.

This means I have to unwind the stack and replay the matrix transformations with the coordinate system set to the target image.

NEWS: I have a (sloooow) software rasterizer for triangles now and can render the full “Hello Mesh” example. Will post the files somewhen this week.

Meanwhile, I’m baffled by Cargo-Bot.

Again, an update of the wrapper is up on pastebin for one month:

It includes everything it needs, where “includes” includes vector (which i updated slightly, so don’t use the original vector.lua).

What’s new?

The mess is a mesh. Or the other way round? It is enough of a mesh to run the Hello Mesh example. I’ve written a pure Lua triangle rasterizer for it.

A feat (and also a mess) was setContext() because of the lower left coordinate origin of Codea. Many transformation unwinding and replaying is done to support resetMatrix() as well as rendering shapes and pixels (with a reasonable speed) in Löve Canvases.

Now running:

Examples: Anangrams, Cloth, Gravity, Hello Mesh, Mandelbrot

Games: Asteroyds (better than ever), Can’t Stop, Space Puzzle 8, Backgammon

Not yet: Battle Chips

@Codeslinger… thank you!

@Codeslinger, is there something particular I’m doing in Battle Chips that’s making it hard at your end? Other than lots of translate and resetMatrix (to draw the robots in different elements) I don’t think I’m doing anything that would kink things up.

If there are changes I could make to make things easier, let me know.

Hotfixes for Battle Chips:

Use this conf.lua for a portrait layout:

function love.conf(t)
    t.title = "Battle Chips"
    t.screen.width = 768
    t.screen.height = 1024

If the window is too large for your screen use shift + arrow up / down to move the contents of the window 300 pixels up (or down to normal).

Mark: Many texts are rendered centered. I didn’t follow the whole program flow but it seems that some textMode(CORNER) might help (even if simply for the sake of clarity since CENTER is the default). I suspect some code in the wrapper to set the text mode to center unintentionally. Will look into it.

Hi Guys,

I’m having problems with LoveCodea.lua since the update. I replaced the loveCodify.lua with loveCodea.lua and modified the main.lua in line with that. the new file has vectors.lua in-line. But when I run it I get the following errors:


.\loveCodea.lua:920: attempt to call field ‘newCanvas’ (a nil value)


.\loveCodea.lua:920: in function ‘_initPixelContext’
.\loveCodea.lua:944: in main chunk
[C]: in function ‘require’
main.lua:8 in main chunk
[C]: in function ‘require’
[C]: in function ‘xpcall’

Needless to say this went ‘wooooosh’ above my head. Obviously checked the error messages but the routines involved meant nothing to me.

Anyone else have problems?
Can anyone advise?

I’d love to get back to Love2D prototyping as it’s easier to control my files etc.




Some incompatible changes were made in Löve 0.8.0 . Since this is not a production quality wrapper, I don’t strive for backwards compatibility, this wrapper is for Löve 0.8.0 exclusively. You probably still use 0.7.2 .

Hi Codeslinger,

Thanks for the reply. I thought I had 0.8.0, but I could be wrong. How can you tell? Is their a text file in e Love directory with version details, or can you simply print(“version :”…version).




Run love without arguments. You should see a rubber piggy and the version number. I don’t know of any functions or variables you could test while running at the moment.

Hi Codeslinger,

You won’t believe this - looked for documentation with the installation - very few files and no obvious means of finding it, so I ran the app and presto there it was. I did this whilst loading up the Codea forum and read your note LOL.

I had 0.7.2 still installed - so I downloaded and installed 0.8.0 then tested it with the text drawn sphere I posted recently. It worked - distorted (need to learn about fonts in Love2D) but fine.

Many thanks and an excellent update. Must congratulate you on loveCodea, if you ever get time to complete it I’m sure all the Codea users would be very grateful.

Thanks again.



I don’t think that the wrapper will ever be complete, Codea has too many potent features under the hood that are not easily accessible under Löve.

Quick fix for your sphere drawing:

One: Copy a Courier font into the project folder as “courier.ttf”. On a Mac you can use “/Library/Fonts/Courier New.ttf”.

Two: Use these improved font functions:

_fontcache = {}
_fontname = ""
_fontsize = 17

function fontSize(size)
    local fullname = _fontname .. size
    if _fontcache[fullname] == nil then
        if _fontname == "" then
            _fontcache[fullname] =
            _fontcache[fullname] =, size)
    _fontsize = size

function font(fontname)
    local ttf = fontname .. ".ttf"
    if love.filesystem.isFile(ttf) then
        _fontname = ttf
        _fontname = ""

And for everybody else, provide a “conf.lua” with these contents or else … (you’ll see only the lower half of a sphere; and I had a burning desire of writing … or else …):

function love.conf(t)
    t.title = "Text Sphere" = "Bri_G"
    t.screen.width = 768
    t.screen.height = 1024

I’m at it again (a little bit):

Support for:

  • Examples/Noise

  • juaxix’s Tiny World Space

  • Mark’s Battle Chips (better text rendering)