Lua Data Access
Appearance
This page demonstrates the mw.neowiki Lua API for accessing NeoWiki structured data from templates and modules.
The examples use Module:NeoWikiDemo, a demo module included with NeoWiki.
Reading Property Values
mw.neowiki.getValue() returns a single scalar value. mw.neowiki.getAll() returns all values as a table.
| Property | getValue | getAll |
|---|---|---|
| Founded at | 2005 | 2005 |
| Websites | https://acme.example | https://acme.example |
| Products (relations) | Foo | Foo, Bar, Baz |
Full Subject Data
mw.neowiki.getMainSubject() returns all data for a Subject as a Lua table, enabling templates to render complete data views.
Professional Wiki
| Property | Type | Value(s) |
|---|---|---|
| Websites | url | https://professional.wiki, https://wikibase.consulting |
| Products | relation | NeoWiki, ProWiki |
| Founded at | number | 2019 |
| World domination progress | number | 42 |
| Status | select | Active |
ACME Inc
| Property | Type | Value(s) |
|---|---|---|
| World domination progress | number | 42 |
| Products | relation | Foo, Bar, Baz |
| Founded at | number | 2005 |
| Websites | url | https://acme.example |
| Status | select | Active |
Child Subjects
mw.neowiki.getChildSubjects() returns all non-main Subjects on a page.
Child subjects on ACME Inc: Foo (Product), Bar (Product), Baz (Product)
Module Source
The demo module uses these mw.neowiki functions:
local nw = require( 'mw.neowiki' )
-- Read a single value (always returns a scalar or nil)
nw.getValue( 'Founded at' ) --> 2005
nw.getValue( 'Products' ) --> "Foo" (first value only)
-- Read all values (always returns a 1-indexed table or nil)
nw.getAll( 'Products' ) --> { "Foo", "Bar", "Baz" }
-- Get full subject data
local s = nw.getMainSubject( 'ACME Inc' )
s.id, s.label, s.schema, s.statements
-- Get child subjects
local children = nw.getChildSubjects( 'ACME Inc' )
See Module:NeoWikiDemo for the full source.