User:WhiteWizard/Lua API
From Tapestries MUCK
< User:WhiteWizard(Difference between revisions)
WhiteWizard (Talk | contribs) (→Locks) |
WhiteWizard (Talk | contribs) (→Standard Lua Libraries) |
||
(5 intermediate revisions not shown) | |||
Line 16: | Line 16: | ||
* nil d:set_(success|osuccess|fail|ofail|drop|odrop)(string) - Set success/osuccess/fail/ofail/drop/odrop message. | * nil d:set_(success|osuccess|fail|ofail|drop|odrop)(string) - Set success/osuccess/fail/ofail/drop/odrop message. | ||
* string|int|dbref|lock|nil d:get_prop(string name) - Returns the value of a property or nil. | * string|int|dbref|lock|nil d:get_prop(string name) - Returns the value of a property or nil. | ||
- | * nil d:set_prop(string name, string|int|dbref) - Set a property. | + | * nil d:set_prop(string name, string|int|dbref|lock) - Set a property. |
- | + | ||
* nil d:remove_prop(stirng name) - Delete property if it exists. | * nil d:remove_prop(stirng name) - Delete property if it exists. | ||
- | + | * table d:properties(nil | string base) - Starting at base, or /, get all the properties as a table. | |
- | * table d: | + | * property d:prop(string propname) -- get a propert. |
* string d:pronoun_sub(string source) - Only makes sense on a player object | * string d:pronoun_sub(string source) - Only makes sense on a player object | ||
* nil d:set_flag(string flags) | * nil d:set_flag(string flags) | ||
Line 46: | Line 45: | ||
* string d:lock_string() | * string d:lock_string() | ||
* nil d:set_lock_string() | * nil d:set_lock_string() | ||
- | |||
* nil d:clear_lock() | * nil d:clear_lock() | ||
* array d:connections() | * array d:connections() | ||
Line 55: | Line 53: | ||
* dbref d:create_(room|thing|exit)(string name) | * dbref d:create_(room|thing|exit)(string name) | ||
* nil d:send_home() | * nil d:send_home() | ||
+ | |||
+ | ===Property Class=== | ||
+ | * string p:name() -- Property name. | ||
+ | * string p:path() -- Property path | ||
+ | * int p:type() -- Property type | ||
+ | ** property.string | ||
+ | ** property.integer | ||
+ | ** property.dbref | ||
+ | ** property.lock | ||
+ | * int|dbref|string|lock p:value() | ||
+ | * string p:to_string() | ||
+ | * nil p:set_value(dbref|integer|string|lock) -- Rewrite the property | ||
+ | * bool p:is_propdir() -- true|false | ||
+ | * array p:contents() -- on a propdir returns an array of properties | ||
+ | * string p:parse_mpi() -- Parse the property as MPI | ||
===db global table=== | ===db global table=== | ||
Line 93: | Line 106: | ||
== Multitasking == | == Multitasking == | ||
- | + | * sleep(float seconds) | |
+ | * yield() -- allow other programs to run, and resets your instruction count limit. | ||
+ | * background(return_value) - Places the program in background mode. Return value may be passed if it was called from something that expected one. | ||
== Misc == | == Misc == | ||
* string read() -- Yield until the player enters a string. | * string read() -- Yield until the player enters a string. | ||
* table require(string package) -- Follows the standard Lua package library stuff, but hacked to read from the Muck's registry and programs. | * table require(string package) -- Follows the standard Lua package library stuff, but hacked to read from the Muck's registry and programs. | ||
+ | |||
+ | == Standard Lua Libraries == | ||
+ | These are included as-is unless otherwise noted: | ||
+ | |||
+ | * base | ||
+ | ** sans dofile() for obvious reasons | ||
+ | ** also missing collectgarbage | ||
+ | ** loadstring() removed, it's depricated anyway | ||
+ | ** load() modified, only takes the first two paramaters. mode is forced to "t". | ||
+ | * math | ||
+ | * table | ||
+ | * string | ||
+ | * bit32 | ||
+ | * package | ||
+ | ** This uses a custom loader that uses the Muck's registry system to find in-game programs to require. | ||
+ | ** the module function is removed: it is depricated in 5.2.x and has major flaws documented here: [http://lua-users.org/wiki/LuaModuleFunctionCritiqued] | ||
+ | * os | ||
+ | ** no: execute, getenv, exit, remove, rename, setlocale, tmpname |
Latest revision as of 00:26, 29 May 2013
This is a very quick definition of the (desired) API to access the Muck from Lua.
Contents |
Database
Almost all database access is done through a lua class. In the examples, d refers to a dbref class instance.
dbref class
- string d:desc() - Return the description of the object.
- nil d:set_desc(desc) - Set above.
- string d:name() - Return the name of the object.
- nil d:set_name(name, [password]) - Set the name. Password required for a player.
- string d:unparse() - Returns the name in the long format that includes the dbref and flags.
- integer d:type() - Returns the type of the object. One of: dbref.THING, dbref.PLAYER, dbref.GARBAGE, dbref.EXIT, dbref.ROOM
- bool d.is_(thing|player|garbage|exit|room)() - Returns true if it is of this type.
- bool d:is_valid() - Is > 0 < dbtop and not GARBAGE
- string d:(success|osuccess|fail|ofail|drop|odrop)() - Get success/osuccess/fail/ofail/drop/odrop message.
- nil d:set_(success|osuccess|fail|ofail|drop|odrop)(string) - Set success/osuccess/fail/ofail/drop/odrop message.
- string|int|dbref|lock|nil d:get_prop(string name) - Returns the value of a property or nil.
- nil d:set_prop(string name, string|int|dbref|lock) - Set a property.
- nil d:remove_prop(stirng name) - Delete property if it exists.
- table d:properties(nil | string base) - Starting at base, or /, get all the properties as a table.
- property d:prop(string propname) -- get a propert.
- string d:pronoun_sub(string source) - Only makes sense on a player object
- nil d:set_flag(string flags)
- string d:flags()
- bool d:flag(string flag)
- int d:get_mlevel()
- int d:pennies()
- nil d:set_pennies(int value) - Absolute, not relative.
- nil d:add_pennies(int value) - Relative, negitive removes.
- nil d:force(string command) - @force a player.
- table d:timestamps() - keys: created, last_modified, last_used, use_count
- table d:stats() - Only works on players. Returns a table of # of objects owned by various types and total.
- dbref d:link() what this is linked to.Alias to home for players/things
- nil d:set_link(dbref dest) link an object.
- nil d:unlink() - Unlink an object
- dbref d:owner()
- nil d:set_owner(dbref player)
- nil d:recycle()
- bool d:check_password(string password)
- nil d:move(dbref destination)
- dbref d:location() -- Alias to parent for rooms.
- array d:contents()
- array d:exits()
- bool d:is_locked(dbref player)
- string d:lock_string()
- nil d:set_lock_string()
- nil d:clear_lock()
- array d:connections()
- bool d:is_awake()
- int d:idle_time() - Lowest idle time from all connections.
- int d:con_time()
- array d:owns()
- dbref d:create_(room|thing|exit)(string name)
- nil d:send_home()
Property Class
- string p:name() -- Property name.
- string p:path() -- Property path
- int p:type() -- Property type
- property.string
- property.integer
- property.dbref
- property.lock
- int|dbref|string|lock p:value()
- string p:to_string()
- nil p:set_value(dbref|integer|string|lock) -- Rewrite the property
- bool p:is_propdir() -- true|false
- array p:contents() -- on a propdir returns an array of properties
- string p:parse_mpi() -- Parse the property as MPI
db global table
- dbref db.create_room(string name) -- Creates a room in the default environment. Useful for bootstrapping a home or something.
- dbref db.match(string match_text) -- Find an object by name
- dbref db.match_player(string match_text) -- Find a player globally
Locks
lock class as l
- bool l:test(dbref player)
- string l:unparse()
- string l:pretty()
lock global table
- l|nil lock:parse_lock(string lock_text)
Globals
- caller
- me
- trigger
- program
Connection
c = a connection object
- array connection.connections()
- dbref c:player()
- int c:idle()
- nil c:boot()
- int c:con_time()
Muck
- string muck.version
- string muck.name
- string|int|bool muck.sys_param(string name)
- string muck.timezone
Multitasking
- sleep(float seconds)
- yield() -- allow other programs to run, and resets your instruction count limit.
- background(return_value) - Places the program in background mode. Return value may be passed if it was called from something that expected one.
Misc
- string read() -- Yield until the player enters a string.
- table require(string package) -- Follows the standard Lua package library stuff, but hacked to read from the Muck's registry and programs.
Standard Lua Libraries
These are included as-is unless otherwise noted:
- base
- sans dofile() for obvious reasons
- also missing collectgarbage
- loadstring() removed, it's depricated anyway
- load() modified, only takes the first two paramaters. mode is forced to "t".
- math
- table
- string
- bit32
- package
- This uses a custom loader that uses the Muck's registry system to find in-game programs to require.
- the module function is removed: it is depricated in 5.2.x and has major flaws documented here: [1]
- os
- no: execute, getenv, exit, remove, rename, setlocale, tmpname