This information applies to the PICO-8 0.1.2
release.
This document is here to help folks with a proficiency in Lua understand the limitations and discrepencies between Lua and PICO-8's Lua.
You can always view the manual or yellowafterlife's extended manual.
- anything written in uppercase the PICO-8 editor or .p8 is made lowercase by the editor. → editing the .p8 file directly can work_
- multi line comments don't work correctly. → use single lines to get around this
print(function() end)
segfaults → wrapping it in atostring()
will fix itprint
takes three arguments (string,x,y) → useprinth()
instead- PICO-8's Lua supports a few Compound assignment operators:
+=
,-=
,*=
,/=
,%=
- PICO-8's Lua has single line shorthand for if then else operators. → Compare to ternary?: PICO-8 Lua:
IF (NOT B) THEN I=1 J=2 END
vs Lua:i,j = not b and 1,j or i,2
. - PICO-8's Lua has a different precision (16:16 fixed point) vs Lua's double-precision floating-point.
- PICO-8's Lua has additional Comparison operators/relational operators for "Not Equal To" (
~=
):!=
ipairs
does not have the proper indexing and will loop over the first element infinitely . → usepairs
instead- There is no
io
object. → There is technically "Cartride Data" that you can use for persistant information _VERSION
exists, but can't be accessed via the editor. → It returnsLua 5.2
.load
has been overwritten with a PICO-8 function.- PICO-8 introduces many other global functions (see manual).
rawlen
returns small fractions [incorrect value][s|g]etmetatable
needs to be tested.- There are general rounding errors:
print("-1"*1 == -1") -- false
- strings that use upper case pattern matching will not be able to be entered into the editor directly.
string.byte
returns a fraction [incorrect value]string.char
operates differently:
string.dump
returns the charactersva
but offset I think? [incorrect value?]string.find
returns small fractions [invalid indexes]string.gmatch
does not return a working iterator [broken iterator index]string.gsub
does not return the correct index [incorrect second value]string.len
returns a rather small fraction [incorrect value] → use the#
operator insteadstring.[upper|lower]
while both of these functions technically work correctly, because the char table has had the upper case characters removed, it will not work as intended.
table.insert(t,o)
does not insert the proper key. → useadd(t,o)
insteadtable.insert(t,p,o)
does not insert the proper key. Attempting to insert beyond table initialization causes an position out of bounds error.table.remove(t,p)
removes the correct value, but then assocates every following value with the key before it. → usedel(t,o)
instead
math.a[cos|sin|tan][2]
does not work correctly. [Rounding errors?] → useatan2()
instead ofmath.atan2()
. Untested versions heremath.[floor|ceil]
returns input [incorrect value] → useflr()
instead. Formath.ceil()
, usefunction ceil(x) return -flr(-x) end
math.[cos|sin]
return zero [incorrect value] → usecos()
andsin()
. Functions take 0..1 instead of 0..PI*2, andsin()
is inverted.math.tan
does not work correctly. [Rounding errors?] → use math instead:math.[cos|sin|tan]h
does not work correctly. [Rounding errors?]math.[deg|rad]
return zero [incorrect value] → _use math instead:math.[exp|log]
does not work correctly [Rounding errors?]math.log10
is nil [does not exist]math.pow
does not work correctly [returns -maxint] → use the^
operator insteadmath.modf
returns two zeros [incorrect value] → use the%
operator insteadmath.sqrt
does not work correctly [Rounding errors?] → usesqrt()
insteadmath.random
does not work correctly [returns zero] → usernd()
insteadmath.randomseed
cannot be verified until math.random is fixed [dependency issue] → usesrand()
insteadmath.frexp
does not return a value [incorrect return type] → butmath.ldexp()
works for some reason!math.huge
is 0.5 [incorrect value and type]math.pi
is 5.341e-05 [incorrect value] → use a fixed value instead, e.g.: 3.14159
os.date
works correctly, but due to a lack of upper case characters, it does not render correctly.os.time
returns the incorrect value [rounding issues]os.getenv
works correctly, but the editor cannot write upper case characters.os.difftime
does not work correctly, but I think that this could be used to getos.time()
to work correctly.os.re[name|move]
this probably works, but operates where the binary forpico8
is located.os.clock
doesn't work correctly, but could probably be scaled to the correct value. → pico8 is forced at 30fps; calculate time by incrementing a variable in_update()
by 1/30.
this function has not been compared, but seems intact.
bit32
table contains:extract
,bnot
,rrotate
,arshift
,btest
,bxor
,replace
,band
,lshift
,rshift
,lrotate
,bor
shutdown
quits thepico8
binary._update_buttons
function. Has no arguments._p8_program
function. Causes out of memory error when called.ls
function. Lists cache cart directory as root and colors output using print statement.decompress
function. Not sure what it does.c
variable may sometime be globally set. Seems to be a scope error for some other function.trace
function. I'm guessing it's for the runtime errors.all
function. Not sure what it does._set_mainloop_exists
function. Most likely toggles a variable in a local scope.stop
function. Stops game at current point so you can debug things.
Just so you know, compress / decompress / all / shutdown are all documented. The last two are even in the manual.
trace() returns the current call stack.