Log In  
Follow
Siapran
Parens-8 V3
by Siapran
SHOW MORE

After a long journey, I'm proud to present to you...

parens-8 v3!

...Along with the obligatory demo, a cart that stores its entire game code in ROM:

Cart #parens8_v3_demo-0 | 2024-03-10 | Code ▽ | Embed ▽ | No License
16

Parens-8 is a tool for bypassing the pico-8 token limit. It takes up 5% of the allowed 8192 tokens, and gives you practically infinite code space in return: store extra code in strings or cart ROM, load it during init, run it like regular Lua code.

Parens-8 is designed for maximum interoperability with Lua. Functions, tables, values and coroutines can be passed and used seamlessly between Lua and parens-8. Think of parens-8 as Lua semantics with Lisp syntax.

local a, b, c = parens8("1 2 3")
?(b == 2) -- true

local myfunction = parens8"(fn(x) (print x))"
myfunction(42) -- prints 42

-- use the lua multiline string syntax: [[]]
parens8[[
     (set foo 256)
     (set bar (fn (a b)
          (when a
               (print b)
               (print "a was false or nil")
          )
     ))
]]

bar(foo, "hello") -- prints "hello"
bar(false, "goodbye") -- prints "a was false or nil"

The new v3 implementation greatly improves on previous versions:

  • significantly faster (50-100% speedup)
  • lower memory usage
  • more extensions (variadics, table constructors, field syntax)
  • safer (no nil invisibility issue)

For more information and documentation, please refer to the parens-8 Github repository.

P#142700 2024-03-10 00:29

SHOW MORE

first off, a demo. here's a cart that stores the entirety of its game logic in its sprite sheet:

Cart #baloonbomber_rom-0 | 2023-10-06 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
19

this is a parens-8 port of an old cart of mine. it has the lua code for the parens-8 language, and then parens-8 code for loading parens-8 game logic from ROM. you can find the full source for the game logic here

parens-8 is a lisp interpreter/compiler designed specifically to bypass the lua token limit.
the idea: use a portion of your cart (between 330 and 900 tokens, depending on your use case) to store the parens-8 interpreter, offload performance noncritical code into strings, and then optionally into ROM.

the parens-8 github repo has detailed instructions on how to achieve this, and how to customize parens-8 to best fit your project.

let's look at an excerpt of the original lua code for baloonbomber:

function make_explosion( x, y, r )
    local explosion = { x = x, y = y, r = r, ttl = 10, fg = true }
    function explosion:update( )
        if self.ttl < 5 then
            self.x -= speed
            make_smoke(self.x + rnd(self.r) - self.r / 2,
                       self.y + rnd(self.r) - self.r / 2)
        end
    end
    function explosion:draw( )
        circfill(self.x, self.y, self.r * min(self.ttl / 8, 1),
                 explosion_colors[11 - self.ttl] or 0)
    end
    add_particle(explosion)
end

and here is the corresponding parens-8 implementation:

(set make_explosion (fn (x y r) (add particles (zip
    (split "x,y,r,ttl,fg,update,draw") (pack
        x y r 10 1
        (fn (self) (env self (when (< ttl 5) (id
            (set x (- x speed))
            (make_smoke (- (+ x (rnd r)) (/ r 2))
                        (- (+ y (rnd r)) (/ r 2)))))))
        (fn (self) (env self
            (circfill
                x y
                (* r (min (/ ttl 8) 1))
                (or ([] explosion_colors (- 11 ttl)) 0)))))))))

the syntax may seem hostile, but the semantics are very much similar to that of lua. you may even identify common pico-8 patterns like using split or remapping _ENV.

parens-8 comes with a pretty significant performance overhead (see github repo for benchmarks), so while calls to the pico-8 api and lua functions are unaffected, tight loops and the like are dramatically slower in parens-8. make sure you minimize the cpu time spent in parens-8 code.

things you could probably offload as parens-8 code:

  • your _init, _update and _draw functions
  • complicated actor behavior where different actors have very different logic (coroutines are supported!)
  • weird glue code that pokes a bunch of flags, sets up pal calls, etc

things you definitely shouldn't write in parens-8:

  • your particle system
  • your rendering routines
  • 3d rotation matrix computations

baloonbomber - parens-8 edition is the answer to the question "can I offload my entire game to ROM":
yes, but you probably shouldn't.

P#135521 2023-10-06 19:06 ( Edited 2023-10-10 03:53)

SHOW MORE

Github repo

I was tired of navigating through all my code in a single file, so I made a simple tool for building carts code from multiple smaller files.

Nothing fancy as of now, but I hope it can save some people some time.

P#37230 2017-02-06 17:22 ( Edited 2017-02-06 22:22)

SHOW MORE

Cart #37025 | 2017-02-01 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
5

Here's a small cart I made to teach programming to a friend.
It's far from complete, and I'll post more updates as they make progress.

I restrained myself from using lua tricks like coroutines, metatables, and abusive oop, so the code could be kept as much approachable as possible.

Direction keys to move, C/Z to cycle lifes.

P#37028 2017-02-01 18:09 ( Edited 2017-02-02 16:59)

SHOW MORE

Cart #20313 | 2016-05-08 | Code ▽ | Embed ▽ | No License
7

Organ is a simple sfx organizer.

When I make music with the pico8 tracker, I usually end up with an unreadable mess of samples that have nothing in common.

This utility lets you switch sfx indexes and update the song data accordingly.
You can either specify a filename in the code (still waiting for a usable ls()), or paste the song data of another cart manually.

The data is saved on the editor itself (even when a filename is specified). To save it to your music cart, you'll need to edit it manually (I'll make a better UI in the future).

I may or may not extend this to make a music compression utility :T

P#20310 2016-05-08 08:49 ( Edited 2016-05-08 13:59)

SHOW MORE

Cart #11461 | 2015-07-05 | Code ▽ | Embed ▽ | No License
22

A veeery old thing I did in 2013 when I didn't really know how to program yet.
I was bored in math class so I did this thingy on my calculator.

I pretty much copy-pasted the whole thing and applied a few fixes for pico8, but it's really the same old code (ewww...)
At the time, the thing blurted out a frame every 28 seconds. Needless to say I was REALLY bored.

nostalgia link to the original code
A friend of mine already adapted it for Love2D a while ago, with much better results (video).

For fun times, try doing what I first did when I wrote this code: setting elasticity above 1/2.

EDIT: oh, yeah, you can control the camera with the arrow keys and reset the cloth with x

P#11458 2015-07-05 08:49 ( Edited 2015-09-06 16:57)

SHOW MORE

Cart #11243 | 2015-06-11 | Code ▽ | Embed ▽ | No License
4

I WAS BORED OK

P#11244 2015-06-11 11:56 ( Edited 2015-06-11 20:28)

SHOW MORE

Cart #10893 | 2015-05-23 | Code ▽ | Embed ▽ | No License
5

Update: tweaked the cooldown

Cart #10888 | 2015-05-23 | Code ▽ | Embed ▽ | No License
5

just a simple demonstration of the undocumented feature of stat(x)
using the demo musics of course

feel free to use it in your music carts :D

P#10885 2015-05-23 15:38 ( Edited 2015-05-23 21:36)

Follow Lexaloffle:          
Generated 2024-03-19 02:12:03 | 0.082s | Q:32