Skip to content
This repository was archived by the owner on Dec 29, 2024. It is now read-only.

Commit 2c1b23d

Browse files
authored
Add LuaObjectMetatable type (#149)
1 parent 6d6248a commit 2c1b23d

26 files changed

+1211
-213
lines changed

config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def get_doc_classes():
2626
"LuaError",
2727
"LuaTuple",
2828
"LuaCallableExtra",
29+
"LuaObjectMetatable",
30+
"LuaDefaultObjectMetatable",
2931
]
3032

3133
def get_doc_path():

doc_classes/LuaAPI.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<class name="LuaAPI" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
2+
<class name="LuaAPI" inherits="RefCounted" version="4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
33
<brief_description>
44
Execute Lua code at runtime and make your own API.
55
</brief_description>
@@ -105,8 +105,8 @@
105105
</method>
106106
</methods>
107107
<members>
108-
<member name="permissive" type="bool" setter="set_permissive" getter="get_permissive" default="true">
109-
When set to true all methods will be allowed on Objects be default and lua_fields is treated as a blacklist. When set to false, lua_fields is treated as a whitelist.
108+
<member name="object_metatable" type="LuaObjectMetatable" setter="set_object_metatable" getter="get_object_metatable" default="LuaDefaultObjectMetatable">
109+
This is the default LuaMetatable to use for object which do not define a lua_metatable field. By default it is a LuaDefaultObjectMetatable. You can change this to a custom metatable to change the behavior of all objects.
110110
</member>
111111
<member name="memory_limit" type="int" setter="set_memory_limit" getter="get_memory_limit" default="0">
112112
Sets the memory limit for the state in bytes. If the limit is 0, there is no limit.

doc_classes/LuaCallableExtra.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<class name="LuaCallableExtra" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
2+
<class name="LuaCallableExtra" inherits="RefCounted" version="4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
33
<brief_description>
44
A tuple.
55
</brief_description>

doc_classes/LuaCoroutine.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<class name="LuaCoroutine" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
2+
<class name="LuaCoroutine" inherits="RefCounted" version="4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
33
<brief_description>
44
A coroutine.
55
</brief_description>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<class name="LuaDefaultObjectMetatable" inherits="LuaObjectMetatable" version="4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3+
<brief_description>
4+
The default LuaObjectMetatable used by the LuaAPI class as the object_metatable value.
5+
</brief_description>
6+
<description>
7+
This metatable by default checks if the object has a lua_fields method. If it does depending on how permissice is set. The listed fields will be allowed or disallowed.
8+
This metatable also checks if the object overrides any of the metamethods, if it does it will call the overridden method.
9+
</description>
10+
<tutorials>
11+
</tutorials>
12+
<members>
13+
<member name="permissive" type="bool" setter="set_permissive" getter="get_permissive" default="true">
14+
Sets weather the Objects lua_fields method is treated as a whitelist or a blacklist. If true, the fields method is treated as a blacklist and returned fields will be disallowed. If false, the fields method is treated as a whitelist and returned fields will be allowed.
15+
</member>
16+
</members>
17+
</class>

doc_classes/LuaError.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<class name="LuaError" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
2+
<class name="LuaError" inherits="RefCounted" version="4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
33
<brief_description>
44
LuaAPI Error.
55
</brief_description>

doc_classes/LuaObjectMetatable.xml

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<class name="LuaObjectMetatable" inherits="RefCounted" version="4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
3+
<brief_description>
4+
Represents a Lua Object Metatable.
5+
</brief_description>
6+
<description>
7+
This interface class allows for the definition of lua metamethods to be used for an objects metatable. Objects can define a [code]lua_metatable[/code] property that returns a LuaObjectMetatable. This metatable will be used for the object when it is passed to Lua. If one does not exists the luaAPI.object_metatable will be used instead.
8+
<tutorials>
9+
</tutorials>
10+
<methods>
11+
<method name="__add" qualifiers="virtual">
12+
<return type="Variant" />
13+
<param index="0" name="obj" type="Object" />
14+
<param index="1" name="lua" type="LuaAPI" />
15+
<param index="2" name="other" type="Variant" />
16+
<description>
17+
The addition (+) operation. If any operand for an addition is not a number, Lua will try to call a metamethod. It starts by checking the first operand (even if it is a number); if that operand does not define a metamethod for __add, then Lua will check the second operand. If Lua can find a metamethod, it calls the metamethod with the two operands as arguments, and the result of the call (adjusted to one value) is the result of the operation. Otherwise, if no metamethod is found, Lua raises an error.
18+
</description>
19+
</method>
20+
<method name="__band" qualifiers="virtual">
21+
<return type="Variant" />
22+
<param index="0" name="obj" type="Object" />
23+
<param index="1" name="lua" type="LuaAPI" />
24+
<param index="2" name="other" type="Variant" />
25+
<description>
26+
The bitwise AND (&) operation. Behavior similar to the addition operation, except that Lua will try a metamethod if any operand is neither an integer nor a float coercible to an integer
27+
</description>
28+
</method>
29+
<method name="__bnot" qualifiers="virtual">
30+
<return type="Variant" />
31+
<param index="0" name="obj" type="Object" />
32+
<param index="1" name="lua" type="LuaAPI" />
33+
<description>
34+
The bitwise NOT (unary ~) operation. Behavior similar to the bitwise AND operation.
35+
</description>
36+
</method>
37+
<method name="__bor" qualifiers="virtual">
38+
<return type="Variant" />
39+
<param index="0" name="obj" type="Object" />
40+
<param index="1" name="lua" type="LuaAPI" />
41+
<param index="2" name="other" type="Variant" />
42+
<description>
43+
The bitwise OR (|) operation. Behavior similar to the bitwise AND operation.
44+
</description>
45+
</method>
46+
<method name="__bxor" qualifiers="virtual">
47+
<return type="Variant" />
48+
<param index="0" name="obj" type="Object" />
49+
<param index="1" name="lua" type="LuaAPI" />
50+
<param index="2" name="other" type="Variant" />
51+
<description>
52+
The bitwise exclusive OR (binary ~) operation. Behavior similar to the bitwise AND operation.
53+
</description>
54+
</method>
55+
<method name="__call" qualifiers="virtual">
56+
<return type="Variant" />
57+
<param index="0" name="obj" type="Object" />
58+
<param index="1" name="lua" type="LuaAPI" />
59+
<param index="2" name="args" type="LuaTuple" />
60+
<description>
61+
The bitwise NOT (unary ~) operation. Behavior similar to the bitwise AND operation.
62+
</description>
63+
</method>
64+
<method name="__concat" qualifiers="virtual">
65+
<return type="Variant" />
66+
<param index="0" name="obj" type="Object" />
67+
<param index="1" name="lua" type="LuaAPI" />
68+
<param index="2" name="other" type="Variant" />
69+
<description>
70+
The concatenation (..) operation. Behavior similar to the addition operation, except that Lua will try a metamethod if any operand is neither a string nor a number (which is always coercible to a string).
71+
</description>
72+
</method>
73+
<method name="__div" qualifiers="virtual">
74+
<return type="Variant" />
75+
<param index="0" name="obj" type="Object" />
76+
<param index="1" name="lua" type="LuaAPI" />
77+
<param index="2" name="other" type="Variant" />
78+
<description>
79+
The division (/) operation. Behavior similar to the addition operation.
80+
</description>
81+
</method>
82+
<method name="__eq" qualifiers="virtual">
83+
<return type="bool" />
84+
<param index="0" name="obj" type="Object" />
85+
<param index="1" name="lua" type="LuaAPI" />
86+
<param index="2" name="other" type="Variant" />
87+
<description>
88+
The equal (==) operation. Behavior similar to the addition operation, except that Lua will try a metamethod only when the values being compared are either both tables or both full userdata and they are not primitively equal. The result of the call is always converted to a boolean.
89+
</description>
90+
</method>
91+
<method name="__gc" qualifiers="virtual">
92+
<return type="LuaError" />
93+
<param index="0" name="obj" type="Object" />
94+
<param index="1" name="lua" type="LuaAPI" />
95+
<description>
96+
https://www.lua.org/manual/5.4/manual.html#2.5.3
97+
</description>
98+
</method>
99+
<method name="__idiv" qualifiers="virtual">
100+
<return type="Variant" />
101+
<param index="0" name="obj" type="Object" />
102+
<param index="1" name="lua" type="LuaAPI" />
103+
<param index="2" name="other" type="Variant" />
104+
<description>
105+
The floor division (//) operation. Behavior similar to the addition operation.
106+
</description>
107+
</method>
108+
<method name="__index" qualifiers="virtual">
109+
<return type="Variant" />
110+
<param index="0" name="obj" type="Object" />
111+
<param index="1" name="lua" type="LuaAPI" />
112+
<param index="2" name="index" type="String" />
113+
<description>
114+
The indexing access operation table[key]. This event happens when table is not a table or when key is not present in table. The metavalue is looked up in the metatable of table.
115+
116+
The metavalue for this event can be either a function, a table, or any value with an __index metavalue. If it is a function, it is called with table and key as arguments, and the result of the call (adjusted to one value) is the result of the operation. Otherwise, the final result is the result of indexing this metavalue with key. This indexing is regular, not raw, and therefore can trigger another __index metavalue.
117+
</description>
118+
</method>
119+
<method name="__le" qualifiers="virtual">
120+
<return type="bool" />
121+
<param index="0" name="obj" type="Object" />
122+
<param index="1" name="lua" type="LuaAPI" />
123+
<param index="2" name="other" type="Variant" />
124+
<description>
125+
The less equal (<=) operation. Behavior similar to the less than operation.
126+
</description>
127+
</method>
128+
<method name="__len" qualifiers="virtual">
129+
<return type="int" />
130+
<param index="0" name="obj" type="Object" />
131+
<param index="1" name="lua" type="LuaAPI" />
132+
<description>
133+
The length (#) operation. If the object is not a string, Lua will try its metamethod. If there is a metamethod, Lua calls it with the object as argument, and the result of the call (always adjusted to one value) is the result of the operation. If there is no metamethod but the object is a table, then Lua uses the table length operation. Otherwise, Lua raises an error.
134+
</description>
135+
</method>
136+
<method name="__lt" qualifiers="virtual">
137+
<return type="bool" />
138+
<param index="0" name="obj" type="Object" />
139+
<param index="1" name="lua" type="LuaAPI" />
140+
<param index="2" name="other" type="Variant" />
141+
<description>
142+
The less than (<) operation. Behavior similar to the addition operation, except that Lua will try a metamethod only when the values being compared are neither both numbers nor both strings. Moreover, the result of the call is always converted to a boolean.
143+
</description>
144+
</method>
145+
<method name="__metatable" qualifiers="virtual">
146+
<return type="Variant" />
147+
<param index="0" name="obj" type="Object" />
148+
<param index="1" name="lua" type="LuaAPI" />
149+
<description>
150+
If object does not have a metatable, returns nil. Otherwise, if the object's metatable has a __metatable field, returns the associated value. Otherwise, returns the metatable of the given object.
151+
</description>
152+
</method>
153+
<method name="__mod" qualifiers="virtual">
154+
<return type="Variant" />
155+
<param index="0" name="obj" type="Object" />
156+
<param index="1" name="lua" type="LuaAPI" />
157+
<param index="2" name="other" type="Variant" />
158+
<description>
159+
The modulo (%) operation. Behavior similar to the addition operation.
160+
</description>
161+
</method>
162+
<method name="__mul" qualifiers="virtual">
163+
<return type="Variant" />
164+
<param index="0" name="obj" type="Object" />
165+
<param index="1" name="lua" type="LuaAPI" />
166+
<param index="2" name="other" type="Variant" />
167+
<description>
168+
The multiplication (*) operation. Behavior similar to the addition operation.
169+
</description>
170+
</method>
171+
<method name="__newindex" qualifiers="virtual">
172+
<return type="LuaError" />
173+
<param index="0" name="obj" type="Object" />
174+
<param index="1" name="lua" type="LuaAPI" />
175+
<param index="2" name="index" type="String" />
176+
<param index="3" name="value" type="Variant" />
177+
<description>
178+
The indexing assignment table[key] = value. Like the index event, this event happens when table is not a table or when key is not present in table. The metavalue is looked up in the metatable of table.
179+
180+
Like with indexing, the metavalue for this event can be either a function, a table, or any value with an __newindex metavalue. If it is a function, it is called with table, key, and value as arguments. Otherwise, Lua repeats the indexing assignment over this metavalue with the same key and value. This assignment is regular, not raw, and therefore can trigger another __newindex metavalue.
181+
182+
Whenever a __newindex metavalue is invoked, Lua does not perform the primitive assignment. If needed, the metamethod itself can call rawset to do the assignment.
183+
</description>
184+
</method>
185+
<method name="__pow" qualifiers="virtual">
186+
<return type="Variant" />
187+
<param index="0" name="obj" type="Object" />
188+
<param index="1" name="lua" type="LuaAPI" />
189+
<param index="2" name="other" type="Variant" />
190+
<description>
191+
The exponentiation (^) operation. Behavior similar to the addition operation.
192+
</description>
193+
</method>
194+
<method name="__shl" qualifiers="virtual">
195+
<return type="Variant" />
196+
<param index="0" name="obj" type="Object" />
197+
<param index="1" name="lua" type="LuaAPI" />
198+
<param index="2" name="other" type="Variant" />
199+
<description>
200+
The bitwise left shift (<<) operation. Behavior similar to the bitwise AND operation.
201+
</description>
202+
</method>
203+
<method name="__shr" qualifiers="virtual">
204+
<return type="Variant" />
205+
<param index="0" name="obj" type="Object" />
206+
<param index="1" name="lua" type="LuaAPI" />
207+
<param index="2" name="other" type="Variant" />
208+
<description>
209+
The bitwise right shift (>>) operation. Behavior similar to the bitwise AND operation.
210+
</description>
211+
</method>
212+
<method name="__sub" qualifiers="virtual">
213+
<return type="Variant" />
214+
<param index="0" name="obj" type="Object" />
215+
<param index="1" name="lua" type="LuaAPI" />
216+
<param index="2" name="other" type="Variant" />
217+
<description>
218+
The subtraction (-) operation. Behavior similar to the addition operation.
219+
</description>
220+
</method>
221+
<method name="__tostring" qualifiers="virtual">
222+
<return type="String" />
223+
<param index="0" name="obj" type="Object" />
224+
<param index="1" name="lua" type="LuaAPI" />
225+
<description>
226+
The tostring operation. Used when tostring is called on the object.
227+
</description>
228+
</method>
229+
<method name="__unm" qualifiers="virtual">
230+
<return type="Variant" />
231+
<param index="0" name="obj" type="Object" />
232+
<param index="1" name="lua" type="LuaAPI" />
233+
<description>
234+
The negation (unary -) operation. Behavior similar to the addition operation.
235+
</description>
236+
</method>
237+
</methods>
238+
239+
</methods>
240+
<members>
241+
</members>
242+
<constants>
243+
</constants>
244+
</class>

doc_classes/LuaTuple.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<class name="LuaTuple" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
2+
<class name="LuaTuple" inherits="RefCounted" version="4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
33
<brief_description>
44
A Lua Tuple.
55
</brief_description>

project/testing/tests/LuaAPI.call_function.gd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ func _ready():
88
id = 9970
99

1010
lua = LuaAPI.new()
11-
lua.permissive = true
1211

1312
# testName and testDescription are for any needed context about the test.
1413
testName = "LuaAPI.call_function"

project/testing/tests/LuaAPI.expose_constructor.gd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ func _ready():
1212
id = 9950
1313

1414
lua = LuaAPI.new()
15-
lua.permissive = true
1615
var err = lua.push_variant("TestObj", TestObject.new)
1716
if err is LuaError:
1817
errors.append(err)

0 commit comments

Comments
 (0)