Lib sqlite function
Console program80 lines of .st200 lines of generated C
root row root row module row, SQLITE_OK is 0
On this page
The .st files#
intent.st
structop {
type_app {
exec = {
lang = "C"
standard = "c11"
}
}
lib_provider {
C_lang = {
source = "StructOp/c"
version = "@latest"
}
Db = {
source = "C/sqlite3"
version = "@latest"
}
}
}main.st
# A library call whose callback list stands in a function body, at the root and in a module:
# each callback is written before the function that passes it. The module reads a provider constant.
ability "value" "db" {
type = Sqlite3
}
ability "sqlite3_open" "Open" {
filename = ":memory:"
target = ability.value.db
}
ability "function" "list_rows" {
body = [ability.sqlite3_exec.List]
}
ability "sqlite3_exec" "List" {
db = ability.value.db
sql = "SELECT 1 UNION ALL SELECT 2"
callback = [ability.print.Row]
}
ability "print" "Row" {
message = "root row"
}
ability "call" "Run" {
function = ability.function.list_rows
depends_on = [ability.sqlite3_open.Open]
}
module "m" {
source = "./modules/m"
depends_on = [ability.call.Run]
}modules/m/main.st
ability "value" "db" {
type = Sqlite3
}
ability "sqlite3_open" "Open" {
filename = ":memory:"
target = ability.value.db
}
ability "function" "list_rows" {
body = [ability.sqlite3_exec.List]
}
ability "sqlite3_exec" "List" {
db = ability.value.db
sql = "SELECT 1"
callback = [ability.print.Row]
}
ability "print" "Row" {
message = "module row, SQLITE_OK is ${const.SQLITE_OK}"
}
ability "call" "Run" {
function = ability.function.list_rows
depends_on = [ability.sqlite3_open.Open]
}Input, plan and generated C#
bind/sqlite3.bind.st · hints for structop bind
bind/sqlite3.bind.st · hints for structop bind
bind "sqlite3" {
header = "sqlite3.h"
package = "sqlite3"
prefix = ["sqlite3_", "SQLITE_"]
}
function "sqlite3_exec" {
names = ["db"]
out_text = { errmsg = "sqlite3_free" }
arg_names = { callback = ["", "count", "values", "columns"] }
}
function "sqlite3_close" {
names = ["db"]
}structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.value.db
+ ability.sqlite3_open.Open
+ ability.function.list_rows
+ ability.sqlite3_exec.List
+ ability.print.Row
+ ability.call.Run
+ module.m.ability.value.db
+ module.m.ability.sqlite3_open.Open
+ module.m.ability.function.list_rows
+ module.m.ability.sqlite3_exec.List
+ module.m.ability.print.Row
+ module.m.ability.call.Run
Plan: 1 to add, 0 to change, 0 to destroy.Generated main.c
To inspect this generated file, select C in intent.st, initialize the project and export its source.
Export locally
structop init
structop apply -source -no-runTry it
structop bind bind/sqlite3.bind.st # from the repository root
cd lib-sqlite-function # a folder holding the .st files above
structop init
structop plan
structop apply