This document demonstrates practical applications of OwnLang's module system through database connectivity and interactive game development examples. It showcases advanced integration patterns combining multiple modules to create sophisticated applications including JDBC database operations, real-time multiplayer games, and network API consumption.
For basic module usage patterns, see Module Architecture. For network-specific examples, see Network Programming Examples.
OwnLang provides database connectivity through the jdbc
module, enabling standard SQL database operations with various database engines including HSQLDB and SQLite.
HSQLDB Database Operations
The HSQLDB example demonstrates file-based database operations with table creation, data insertion, and querying:
Operation | Method Call | Purpose |
---|---|---|
Connection | getConnection("jdbc:hsqldb:file:hsql.db", "", "", "org.hsqldb.jdbcDriver") | Establish database connection |
Table Creation | executeUpdate("CREATE TABLE cities (id IDENTITY, name VARCHAR(32))") | Define schema |
Data Insertion | executeUpdate("INSERT INTO cities (name) VALUES('Киев')") | Insert records |
Data Querying | executeQuery("SELECT id, name FROM cities") | Retrieve data |
Shutdown | execute("SHUTDOWN") | Close database properly |
SQLite Database Operations
The SQLite example shows lightweight database operations with query timeout configuration:
Operation | Code Pattern | Notes |
---|---|---|
Connection | getConnection("jdbc:sqlite:sample.db") | File-based SQLite database |
Timeout | setQueryTimeout(30) | 30-second query timeout |
Schema | create table person (id integer, name string) | Simple table structure |
Data Access | rs.getString("name") , rs.getInt("id") | Typed data retrieval |
Sources: examples/database/hsqldb.own1-18 examples/database/sqlite.own1-20
The pipes game example demonstrates complex application development combining graphics rendering, user input handling, and real-time networking.
The pipes game implements a dual-board system with local and remote player states:
Component | Data Structure | Purpose |
---|---|---|
board[SIZE][SIZE] | 2D array | Local player's game state |
boardGhost[SIZE][SIZE] | 2D array | Remote player's game state |
Cells[] | Object array | Cell type definitions and transitions |
curX , curY | Integers | Local player cursor position |
curGhostX , curGhostY | Integers | Remote player cursor position |
Socket Event Handlers
The game implements several socket event listeners for real-time synchronization:
gameStart
: Initializes both local and ghost boards with server data examples/game/pipes_online.own90-96updateGhostCell
: Updates remote player's cell changes examples/game/pipes_online.own97-100updateGhostCursor
: Synchronizes remote player cursor position examples/game/pipes_online.own101-105gameFinished
: Handles game completion state examples/game/pipes_online.own106-109Sources: examples/game/pipes_online.own1-174
Complex applications often require integration of multiple modules to achieve sophisticated functionality.
The GitHub timeline example demonstrates module composition for API consumption:
Module | Functions Used | Purpose |
---|---|---|
http | http() , thread() | HTTP requests and threading |
json | jsondecode() | JSON response parsing |
functional | foreach() | Data iteration |
date | formatDate() , parseDate() | Date formatting |
std | println , match , length() | Standard operations |
Threaded HTTP Processing
The example shows both synchronous and asynchronous HTTP patterns:
Pattern Matching for Event Types
The application uses pattern matching to handle different GitHub event types, demonstrating complex control flow:
Sources: examples/network/github_timeline.own1-44
These examples demonstrate OwnLang's capabilities for:
The examples showcase how OwnLang's module system enables rapid development of sophisticated applications through clean integration patterns and expressive language constructs.
Sources: examples/database/hsqldb.own examples/database/sqlite.own examples/game/pipes_online.own examples/network/github_timeline.own