From 4eb5841c60afdb8a12602a93e2e68ffdec19bac4 Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Fri, 2 Apr 2021 19:42:19 +0200 Subject: [PATCH] Update OpenMW Lua documentation --- docs/source/conf.py | 2 +- docs/source/reference/lua-scripting/api.rst | 455 ++---------------- .../reference/lua-scripting/overview.rst | 446 ++++++++++++++--- files/CMakeLists.txt | 1 + files/lua_api/CMakeLists.txt | 21 + files/lua_api/README.md | 13 + files/lua_api/coroutine.doclua | 71 +++ files/lua_api/global.doclua | 269 +++++++++++ files/lua_api/math.doclua | 200 ++++++++ files/lua_api/openmw/README.md | 14 + files/lua_api/openmw/async.lua | 52 ++ files/lua_api/openmw/core.lua | 328 +++++++++++++ files/lua_api/openmw/generate_luadoc.sh | 4 + files/lua_api/openmw/nearby.lua | 36 ++ files/lua_api/openmw/query.lua | 116 +++++ files/lua_api/openmw/self.lua | 68 +++ files/lua_api/openmw/ui.lua | 15 + files/lua_api/openmw/util.lua | 150 ++++++ files/lua_api/openmw/world.lua | 34 ++ files/lua_api/string.doclua | 231 +++++++++ files/lua_api/table.doclua | 66 +++ 21 files changed, 2111 insertions(+), 481 deletions(-) create mode 100644 files/lua_api/CMakeLists.txt create mode 100644 files/lua_api/README.md create mode 100644 files/lua_api/coroutine.doclua create mode 100644 files/lua_api/global.doclua create mode 100644 files/lua_api/math.doclua create mode 100644 files/lua_api/openmw/README.md create mode 100644 files/lua_api/openmw/async.lua create mode 100644 files/lua_api/openmw/core.lua create mode 100755 files/lua_api/openmw/generate_luadoc.sh create mode 100644 files/lua_api/openmw/nearby.lua create mode 100644 files/lua_api/openmw/query.lua create mode 100644 files/lua_api/openmw/self.lua create mode 100644 files/lua_api/openmw/ui.lua create mode 100644 files/lua_api/openmw/util.lua create mode 100644 files/lua_api/openmw/world.lua create mode 100644 files/lua_api/string.doclua create mode 100644 files/lua_api/table.doclua diff --git a/docs/source/conf.py b/docs/source/conf.py index 7653b94edf..72bb17adbb 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -176,7 +176,7 @@ html_static_path = [ # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. -#html_extra_path = [] +html_extra_path = ['generated-luadoc'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. diff --git a/docs/source/reference/lua-scripting/api.rst b/docs/source/reference/lua-scripting/api.rst index a7b153c039..f98d4ef074 100644 --- a/docs/source/reference/lua-scripting/api.rst +++ b/docs/source/reference/lua-scripting/api.rst @@ -17,426 +17,69 @@ Engine handler is a function defined by a script, that can be called by the engi | onUpdate(dt) | | Called every frame if game not paused. `dt` is the time | | | | from the last update in seconds. | +----------------------------------+-------------------------------------------------------------+ -| onSave() -> data | Called when the game is saving. | +| onSave() -> data | | Called when the game is saving. May be called in inactive | +| | | state, so it shouldn't use `openmw.nearby`. | +----------------------------------+-------------------------------------------------------------+ -| onLoad(data) | Called on loading with the data previosly returned by onSave| +| onLoad(data) | | Called on loading with the data previosly returned by | +| | | onSave. During loading the object is always in inactive. | +----------------------------------+-------------------------------------------------------------+ | **Only for global scripts** | +----------------------------------+-------------------------------------------------------------+ | onNewGame() | New game is started | +----------------------------------+-------------------------------------------------------------+ -| onPlayerAdded(player) |Player added to game world. The argument is a `Game object`_.| +| onPlayerAdded(player) |Player added to game world. The argument is a `Game object`. | +----------------------------------+-------------------------------------------------------------+ | onActorActive(actor) | Actor (NPC or Creature) becomes active. | +----------------------------------+-------------------------------------------------------------+ +| **Only for local scripts** | ++----------------------------------+-------------------------------------------------------------+ +| onActive() | | Called when the object becomes active (either a player | +| | | came to this cell again, or a save was loaded). | ++----------------------------------+-------------------------------------------------------------+ +| onInactive() | | Object became inactive. Since it is inactive the handler | +| | | can not access anything nearby, but it is possible to send| +| | | an event to global scripts. | ++----------------------------------+-------------------------------------------------------------+ +| onConsume(recordId) | | Called if `recordId` (e.g. a potion) is consumed. | ++----------------------------------+-------------------------------------------------------------+ | **Only for local scripts attached to a player** | +----------------------------------+-------------------------------------------------------------+ | onKeyPress(symbol, modifiers) | | Key pressed. `Symbol` is an ASCII code, `modifiers` is | | | | a binary OR of flags of special keys (ctrl, shift, alt). | +----------------------------------+-------------------------------------------------------------+ -.. _Game object: -Game object reference -===================== +Packages reference +================== + +API packages provide functions that can be called by scripts. I.e. it is a script-to-engine interaction. +A package can be loaded with ``require('')``. +It can not be overloaded even if there is a lua file with the same name. +The list of available packages is different for global and for local scripts. +Player scripts are local scripts that are attached to a player. + ++---------------------------------------------------------+--------------------+---------------------------------------------------------------+ +| Package | Can be used | Description | ++=========================================================+====================+===============================================================+ +|:ref:`openmw.interfaces