Skip to content

Instantly share code, notes, and snippets.

@DanB91
DanB91 / gist:490f85ec0e5b7828a01fd13569240fd0
Last active July 26, 2025 03:31
EM_ASM and EM_ASM_INT in Zig
//A Zig version of emscipten's EM_ASM and EM_ASM_INT
//WARNING: I've only tested 32-bit and 64-bit ints and floats for arguments. Haven't tested other types e.g. bool
//Example:
//em_asm(.{"World!"},
// \\const world = UTF8ToString($0);
// \\console.log(`Hello ${world}`);
// );
pub inline fn em_asm(args: anytype, comptime script: anytype) void {
const toolbox = @import("toolbox.zig");
const std = @import("std");
const root = @import("root");
const ENABLE_PROFILER = if (@hasDecl(root, "ENABLE_PROFILER"))
@field(root, "ENABLE_PROFILER")
else
@compileError("Root module must have ENABLE_PROFILER flag!");
pub const State = struct {
@DanB91
DanB91 / README.txt
Last active November 28, 2022 04:57
Playdate Zig starting point
THIS GIST IS OUT OF DATE! Please use my new project template here to get started with Zig on Playdate:
https://github.com/DanB91/Zig-Playdate-Template
The rest of this is preservied for historical reasons:
This is a small snippet of some code to get you started for developing for the Playdate on Zig. This code should be used as a starting point and may not compile without some massaging. This code has only been tested out on macOS and you'll need to modify the addSharedLibrary() portion of build.zig to output a .dll or .so instead of a .dylib, depending on you platform.
This code will help you produce both an executable for the Playdate simulator and also an executable that actually run on the Playdate hardware.