summaryrefslogtreecommitdiffstatshomepage
path: root/docs/source/luascript/ref-common.rst
blob: c08d3676621b37f76ab2ab1d0ae8bd68be0ee569 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
.. _luascript-ref-common:

Lua Common Types and Globals
============================

.. contents::
    :local:
    :depth: 1


.. _luascript-ref-containers:

Containers
----------

Many properties yield container wrappers.  Container wrappers are cheap to
create, and provide an interface that is similar to a read-only table.  The
complexity of operations may vary.  Container wrappers usually provide most of
these operations:

#c
    Get the number of items in the container.
c[k]
    Returns the item corresponding to the key ``k``, or ``nil`` if the key is
    not present.
pairs(c)
    Iterate over container by key and value.  The key is what you would pass to
    the index operator or the ``get`` method to get the value.
ipairs(c)
    Iterate over container by index and value.  The index is what you would pass
    to the ``at`` method to get the value (this may be the same as the key for
    some containers).
c:empty()
    Returns a Boolean indicating whether there are no items in the container.
c:get(k)
    Returns the item corresponding to the key ``k``, or ``nil`` if the key is
    not present.  Usually equivalent to the index operator.
c:at(i)
    Returns the value at the 1-based index ``i``, or ``nil`` if it is out of
    range.
c:find(v)
    Returns the key for item ``v``, or ``nil`` if it is not in the container.
    The key is what you would pass to the index operator to get the value.
c:index_of(v)
    Returns the 1-based index for item ``v``, or ``nil`` if it is not in the
    container.  The index is what you would pass to the ``at`` method to get the
    value.


.. _luascript-ref-emu:

Emulator interface
------------------

The emulator interface ``emu`` provides access to core functionality.  Many
classes are also available as properties of the emulator interface.

Methods
~~~~~~~

emu.wait(duration, …)
    Yields for the specified duration in terms of emulated time.  The duration
    may be specified as an :ref:`attotime <luascript-ref-attotime>` or a number
    in seconds.  Any additional arguments are returned from the coroutine.
    Returns a Boolean indicating whether the duration expired normally.

    All outstanding calls to ``emu.wait`` will return ``false`` immediately if a
    saved state is loaded or the emulation session ends.  Calling this function
    from callbacks that are not run as coroutines will raise an error.
emu.wait_next_update(…)
    Yields until the next video/UI update.  Any arguments are returned from the
    coroutine.  Calling this function from callbacks that are not run as coroutines
    will raise an error.
emu.wait_next_frame(…)
    Yields until the next emulated frame completes.  Any arguments are returned
    from the coroutine.  Calling this function from callbacks that are not run as
    coroutines will raise an error.
emu.add_machine_reset_notifier(callback)
    Add a callback to receive notifications when the emulated system is reset.
    Returns a :ref:`notifier subscription <luascript-ref-notifiersub>`.
emu.add_machine_stop_notifier(callback)
    Add a callback to receive notifications when the emulated system is stopped.
    Returns a :ref:`notifier subscription <luascript-ref-notifiersub>`.
emu.add_machine_pause_notifier(callback)
    Add a callback to receive notifications when the emulated system is paused.
    Returns a :ref:`notifier subscription <luascript-ref-notifiersub>`.
emu.add_machine_resume_notifier(callback)
    Add a callback to receive notifications when the emulated system is resumed
    after being paused.  Returns a
    :ref:`notifier subscription <luascript-ref-notifiersub>`.
emu.add_machine_frame_notifier(callback)
    Add a callback to receive notifications when an emulated frame completes.
    Returns a :ref:`notifier subscription <luascript-ref-notifiersub>`.
emu.add_machine_pre_save_notifier(callback)
    Add a callback to receive notification before the emulated system state is
    saved.  Returns a
    :ref:`notifier subscription <luascript-ref-notifiersub>`.
emu.add_machine_post_load_notifier(callback)
    Add a callback to receive notification after the emulated system is restored
    to a previously saved state.  Returns a
    :ref:`notifier subscription <luascript-ref-notifiersub>`.
emu.print_error(message)
    Print an error message.
emu.print_warning(message)
    Print a warning message.
emu.print_info(message)
    Print an informational message.
emu.print_verbose(message)
    Print a verbose diagnostic message (disabled by default).
emu.print_debug(message)
    Print a debug message (only enabled for debug builds by default).
emu.lang_translate([context], message)
    Look up a message with optional context in the current localised message
    catalog.  Returns the message unchanged if no corresponding localised
    message is found.
emu.subst_env(string)
    Substitute environment variables in a string.  The syntax is dependent on
    the host operating system.