Skip to content

forjd-hermes-bot/openmp-zig-sqlite-lifecycle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

open.mp Zig SQLite Lifecycle Example

A Zig version of the Rust comparison repo for the open.mp C API.

It demonstrates the full player lifecycle:

  • exports ComponentEntryPoint
  • initializes the open.mp C API
  • registers onPlayerConnect and onPlayerDisconnect
  • loads or creates player state from SQLite on connect
  • applies persisted state to the live player
  • snapshots and saves state on disconnect

Layout

include/ompcapi.h          vendored open.mp C API header
vendor/sqlite/sqlite3.c    vendored SQLite amalgamation
vendor/sqlite/sqlite3.h    vendored SQLite header
build.zig                  shared library + test build
src/main.zig               component, lifecycle, SQLite store, tests

Build

zig build -Doptimize=ReleaseFast

The component shared library will be installed under:

zig-out/lib/

Test

zig build test

Runtime config

Default database path:

scriptfiles/players.sqlite3

Override it with:

OPENMP_PLAYER_DB=/path/to/players.sqlite3 ./omp-server

Notes vs the Rust version

  • Zig imports ompcapi.h directly with @cImport, so there is no bindgen step.
  • SQLite is vendored as the amalgamation and compiled directly into the component.
  • The unsafe/native boundary is flatter and more explicit than Rust.
  • This example keeps DB work synchronous for clarity; for production, consider a worker queue for heavy saves.

About

Example open.mp C API Zig component with SQLite-backed player lifecycle state

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors