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

Commit def7cab

Browse files
authored
Cleanup todo tasks (#125)
1 parent 2a70077 commit def7cab

11 files changed

Lines changed: 51 additions & 64 deletions

File tree

SConstruct

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ sources.append(Glob('src/*.cpp'))
1313
sources.append(Glob('src/classes/*.cpp'))
1414

1515
if env["luaapi_luaver"] == 'jit':
16-
env.Append(CPPDEFINES=['LAPI_LUAJIT', 'LAPI_51'])
16+
env.Append(CPPDEFINES=['LAPI_LUAJIT'])
1717
elif env["luaapi_luaver"] == '5.1':
1818
env.Append(CPPDEFINES=['LAPI_51'])
1919

SCsub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Export('env_lua')
2020
SConscript('external/SCsub')
2121

2222
if env["luaapi_luaver"] == 'jit':
23-
env_lua.Append(CPPDEFINES=['LAPI_LUAJIT', 'LAPI_51'])
23+
env_lua.Append(CPPDEFINES=['LAPI_LUAJIT'])
2424
elif env["luaapi_luaver"] == '5.1':
2525
env_lua.Append(CPPDEFINES=['LAPI_51'])
2626

doc_classes/LuaAPI.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
Execute Lua code at runtime and make your own API.
55
</brief_description>
66
<description>
7-
TODO
8-
</description>
7+
This class represents a lua state and allows you to interact with lua at runtime. You can load files and strings code. Push Callable's as lua functions. And push any Variant as a lua variable.
98
<tutorials>
109
</tutorials>
1110
<methods>

doc_classes/LuaCallableExtra.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
A tuple.
55
</brief_description>
66
<description>
7-
TODO
7+
This is a simple wrapper class to let LuaAPI know you want a little extra info. It is used to request references to the LuaAPI object as an argument and specifie your last argument is a tuple.
88
</description>
99
<tutorials>
1010
</tutorials>
1111
<members>
1212
<member name="tuple" type="bool" setter="set_tuple" getter="get_tuple" default="false">
13-
TODO
13+
Weather or not the last argument is a tuple.
1414
</member>
1515
<member name="wants_ref" type="bool" setter="set_wants_ref" getter="get_wants_ref" default="false">
16-
TODO
16+
Whether or not the function wants a reference to the LuaAPI object.
1717
</member>
1818
<member name="argc" type="int" setter="set_argc" getter="get_argc" default="0">
19-
TODO
19+
The TOTAL number of arguments excluding the tuple if there is one.
2020
</member>
2121
</members>
2222
<methods>
@@ -25,22 +25,22 @@
2525
<param index="0" name="function" type="Callable" />
2626
<param index="1" name="argc" type="int" />
2727
<description>
28-
TODO
28+
Call the function with a tuple as the last argument. Argc is the TOTAL number of arguments excluding the tuple.
2929
</description>
3030
</method>
3131
<method name="with_ref" qualifiers="static">
3232
<return type="LuaCallableExtra" />
3333
<param index="0" name="function" type="Callable" />
3434
<description>
35-
TODO
35+
Call the function with a reference to the LuaAPI object as the first argument.
3636
</description>
3737
</method>
3838
<method name="with_ref_and_tuple" qualifiers="static">
3939
<return type="LuaCallableExtra" />
4040
<param index="0" name="function" type="Callable" />
4141
<param index="1" name="argc" type="int" />
4242
<description>
43-
TODO
43+
Call the function with a reference to the LuaAPI object as the first argument and a tuple as the last argument. Argc is the TOTAL number of arguments excluding the tuple.
4444
</description>
4545
</method>
4646
<method name="set_info">
@@ -50,7 +50,7 @@
5050
<param index="2" name="isTuple" type="bool" />
5151
<param index="3" name="wantsRef" type="bool" />
5252
<description>
53-
TODO
53+
Set CallableExtra info.
5454
</description>
5555
</method>
5656
</methods>

doc_classes/LuaCoroutine.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<return type="Variant" />
4949
<param index="0" name="Args" type="Array" />
5050
<description>
51-
Resumes or starts the coroutine. Will either return a Array of arguments passed by lua in yield() or a LuaError. Arguments are passed to yield() in lua.
51+
Resumes or starts the coroutine. Will either return a Array of arguments passed by lua in yield() or a LuaError. Arguments are passed to yield() in lua. This is a blocking call, it will not return until the coroutine has yielded or finished.
5252
</description>
5353
</method>
5454
<method name="is_done">

doc_classes/LuaError.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<class name="LuaError" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
33
<brief_description>
4-
LuaAPI Error
4+
LuaAPI Error.
55
</brief_description>
66
<description>
77
LuaError contains a error message and type. If a LuaError is ever pushed to the stack it will raise a error in the lua state. Meaning if a exposed GD function returns a lua error. That will raise a error.

doc_classes/LuaTuple.xml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<class name="LuaTuple" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
33
<brief_description>
4-
A tuple.
4+
A Lua Tuple.
55
</brief_description>
66
<description>
7-
TODO
7+
A wrapper for an Array, this type indicates to LuaAPI that the array should be unpacked and trated as multiple arguments. This is useful for functions that take or a variable number of arguments. Or return more than one value.
88
</description>
99
<tutorials>
1010
</tutorials>
@@ -13,66 +13,66 @@
1313
<return type="LuaTuple" />
1414
<param index="0" name="elms" type="Array" />
1515
<description>
16-
TODO
16+
Create a LuaTuple from an array.
1717
</description>
1818
</method>
1919
<method name="push_back">
2020
<return type="void" />
2121
<param index="0" name="var" type="Variant" />
2222
<description>
23-
TODO
23+
Push Variant to back of tuple.
2424
</description>
2525
</method>
2626
<method name="push_front">
2727
<return type="void" />
2828
<param index="0" name="var" type="Variant" />
2929
<description>
30-
TODO
30+
Push Variant to front of tuple.
3131
</description>
3232
</method>
3333
<method name="set_value">
3434
<return type="void" />
3535
<param index="0" name="index" type="int" />
3636
<param index="1" name="var" type="Variant" />
3737
<description>
38-
TODO
38+
Set value at index.
3939
</description>
4040
</method>
4141
<method name="clear">
4242
<return type="void" />
4343
<description>
44-
TODO
44+
Clear tuple.
4545
</description>
4646
</method>
4747
<method name="is_empty">
4848
<return type="bool" />
4949
<description>
50-
TODO
50+
Return true if tuple is empty.
5151
</description>
5252
</method>
5353
<method name="pop_back">
5454
<return type="Variant" />
5555
<description>
56-
TODO
56+
Pop Variant from back of tuple.
5757
</description>
5858
</method>
5959
<method name="pop_front">
6060
<return type="Variant" />
6161
<description>
62-
TODO
62+
Pop Variant from front of tuple.
6363
</description>
6464
</method>
6565
<method name="get_value">
6666
<return type="Variant" />
6767
<param index="0" name="index" type="int" />
6868
<description>
69-
TODO
69+
Get value at index.
7070
</description>
7171
</method>
7272
<method name="to_array">
7373
<return type="Array" />
7474
<description>
75-
TODO
75+
Create an array from tuple.
7676
</description>
7777
</method>
7878
</methods>

src/classes/luaCallableExtra.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ int LuaCallableExtra::call(lua_State *state) {
7272
int noneMulty = l_argc;
7373
LuaCallableExtra *func = (LuaCallableExtra *)LuaState::getVariant(state, 1, OBJ).operator Object *();
7474
if (func == nullptr) {
75-
LuaError *err = LuaError::newError("Error during LuaCallableExtra::call fun==null", LuaError::ERR_RUNTIME);
75+
LuaError *err = LuaError::newError("Error during LuaCallableExtra::call func==null", LuaError::ERR_RUNTIME);
7676
lua_pushstring(state, err->getMessage().ascii().get_data());
7777
lua_error(state);
7878
return 0;

src/classes/luaCoroutine.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ Signal LuaCoroutine::yieldAwait(Array args) {
5858
for (int i = 0; i < args.size(); i++) {
5959
LuaError *err = state.pushVariant(args[i]);
6060
if (err != nullptr) {
61-
// TODO: Handle error
61+
// Raise an error on the lua state, error should be passed to reumse()
62+
state.pushVariant(err);
6263
}
6364
}
6465
return Signal(this, "coroutine_resume");
@@ -145,18 +146,17 @@ Variant LuaCoroutine::resume(Array args) {
145146
return LuaError::newError("Thread is done executing", LuaError::ERR_RUNTIME);
146147
}
147148

148-
int ret = 0;
149149
List<Connection> resume_connections;
150150
get_signal_connection_list("coroutine_resume", &resume_connections);
151151

152152
if (resume_connections.size() > 0) {
153153
if (resume_connections.size() != 1) {
154-
return LuaError::newError("Cannot have more than one coroutine_resume signal connected", LuaError::ERR_RUNTIME);
154+
return LuaError::newError("Cannot have more than one connection to the coroutine_resume signal", LuaError::ERR_RUNTIME);
155155
}
156156

157157
Callable callback = resume_connections[0].callable;
158158
if (!callback.is_valid()) {
159-
return LuaError::newError("Invalid callable connected to coroutine_resume signal", LuaError::ERR_RUNTIME);
159+
return LuaError::newError("Invalid callable connected to the coroutine_resume signal", LuaError::ERR_RUNTIME);
160160
}
161161

162162
disconnect("coroutine_resume", callback);
@@ -172,6 +172,10 @@ Variant LuaCoroutine::resume(Array args) {
172172
Variant returned;
173173
Callable::CallError error;
174174
callback.callp(p_args, args.size(), returned, error);
175+
if (error.error != Callable::CallError::CALL_OK) {
176+
return state.handleError(callback.get_method(), error, p_args, args.size());
177+
}
178+
175179
args.clear();
176180
args.append(returned);
177181
}
@@ -185,9 +189,9 @@ Variant LuaCoroutine::resume(Array args) {
185189

186190
#ifndef LAPI_LUAJIT
187191
int argc = 0;
188-
ret = lua_resume(tState, nullptr, args.size(), &argc);
192+
int ret = lua_resume(tState, nullptr, args.size(), &argc);
189193
#else
190-
ret = lua_resume(tState, args.size());
194+
int ret = lua_resume(tState, args.size());
191195
int argc = lua_gettop(tState);
192196
#endif
193197

@@ -200,7 +204,7 @@ Variant LuaCoroutine::resume(Array args) {
200204

201205
Array toReturn;
202206
for (int i = 1; i <= argc; i++) {
203-
toReturn.append(LuaState::getVariant(tState, i, this));
207+
toReturn.append(state.getVar(i));
204208
}
205209

206210
return toReturn;
@@ -213,17 +217,16 @@ Variant LuaCoroutine::resume(Array args) {
213217
return LuaError::newError("Thread is done executing", LuaError::ERR_RUNTIME);
214218
}
215219

216-
int ret = 0;
217220
TypedArray<Dictionary> resume_connections = get_signal_connection_list("coroutine_resume");
218221
if (resume_connections.size() > 0) {
219222
if (resume_connections.size() != 1) {
220-
return LuaError::newError("Cannot have more than one coroutine_resume signal connected", LuaError::ERR_RUNTIME);
223+
return LuaError::newError("Cannot have more than one connection to the coroutine_resume signal", LuaError::ERR_RUNTIME);
221224
}
222225

223226
bool valid = false;
224227
Callable callback = resume_connections.pop_back().get("callable", &valid);
225228
if (!valid || !callback.is_valid()) {
226-
return LuaError::newError("Invalid callable connected to coroutine_resume signal", LuaError::ERR_RUNTIME);
229+
return LuaError::newError("Invalid callable connected to the coroutine_resume signal", LuaError::ERR_RUNTIME);
227230
}
228231

229232
disconnect("coroutine_resume", callback);
@@ -242,9 +245,9 @@ Variant LuaCoroutine::resume(Array args) {
242245

243246
#ifndef LAPI_LUAJIT
244247
int argc = 0;
245-
ret = lua_resume(tState, nullptr, args.size(), &argc);
248+
int ret = lua_resume(tState, nullptr, args.size(), &argc);
246249
#else
247-
ret = lua_resume(tState, args.size());
250+
int ret = lua_resume(tState, args.size());
248251
int argc = lua_gettop(tState);
249252
#endif
250253

@@ -257,7 +260,7 @@ Variant LuaCoroutine::resume(Array args) {
257260

258261
Array toReturn;
259262
for (int i = 1; i <= argc; i++) {
260-
toReturn.append(LuaState::getVariant(tState, i, this));
263+
toReturn.append(state.getVar(i));
261264
}
262265

263266
return toReturn;

src/lua/lua.hpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
#ifndef LAPI_LUA_HPP
22
#define LAPI_LUA_HPP
33

4-
#ifndef LAPI_51 // LUA 5.4 ONLY
4+
#if defined(LAPI_LUAJIT)
55

6-
extern "C" {
7-
#include <lua/lauxlib.h>
8-
#include <lua/lua.h>
9-
#include <lua/lualib.h>
10-
}
11-
12-
#else
6+
#include <luaJIT/src/lua.hpp>
137

14-
#ifndef LAPI_LUAJIT // LUA 5.1 ONLY
8+
#elif defined(LAPI_51)
159
extern "C" {
1610
#include <lua51/lauxlib.h>
1711
#include <lua51/lua.h>
@@ -20,9 +14,11 @@ extern "C" {
2014

2115
#else // LUAJIT ONLY
2216

23-
#include <luaJIT/src/lua.hpp>
24-
25-
#endif
17+
extern "C" {
18+
#include <lua/lauxlib.h>
19+
#include <lua/lua.h>
20+
#include <lua/lualib.h>
21+
}
2622
#endif
2723

2824
#endif

0 commit comments

Comments
 (0)