You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: code/scripting/api/objs/message.cpp
+45-13Lines changed: 45 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -23,10 +23,7 @@ ADE_VIRTVAR(Name, l_Persona, "string", "The name of the persona", "string", "The
23
23
if (!ade_get_args(L, "o", l_Persona.Get(&idx)))
24
24
returnade_set_error(L, "s", "");
25
25
26
-
if (Personas.empty())
27
-
returnade_set_error(L, "s", "");
28
-
29
-
if (idx < 0 || idx >= (int)Personas.size())
26
+
if (!SCP_vector_inbounds(Personas, idx))
30
27
returnade_set_error(L, "s", "");
31
28
32
29
returnade_set_args(L, "s", Personas[idx].name);
@@ -39,9 +36,6 @@ ADE_VIRTVAR(Index, l_Persona, nullptr, nullptr, "number", "The index of the pers
39
36
if (!ade_get_args(L, "o", l_Persona.Get(&idx)))
40
37
returnade_set_args(L, "i", -1);
41
38
42
-
if (Personas.empty())
43
-
returnade_set_args(L, "i", -1);
44
-
45
39
if (!SCP_vector_inbounds(Personas, idx))
46
40
returnade_set_args(L, "i", -1);
47
41
@@ -51,14 +45,52 @@ ADE_VIRTVAR(Index, l_Persona, nullptr, nullptr, "number", "The index of the pers
51
45
returnade_set_args(L, "i", idx + 1);
52
46
}
53
47
54
-
ADE_FUNC(isValid, l_Persona, NULL, "Detect if the handle is valid", "boolean", "true if valid, false otherwise")
48
+
ADE_VIRTVAR(CustomData, l_Persona, nullptr, "Gets the custom data table for this persona", "table", "The persona's custom data table or nil if an error occurs.")
49
+
{
50
+
int idx = -1;
51
+
52
+
if (!ade_get_args(L, "o", l_Persona.Get(&idx)))
53
+
returnADE_RETURN_NIL;
54
+
55
+
if (!SCP_vector_inbounds(Personas, idx))
56
+
returnADE_RETURN_NIL;
57
+
58
+
if (ADE_SETTING_VAR) {
59
+
LuaError(L, "This property is read only.");
60
+
}
61
+
62
+
auto table = luacpp::LuaTable::create(L);
63
+
64
+
for (constauto& pair : Personas[idx].custom_data)
65
+
{
66
+
table.addValue(pair.first, pair.second);
67
+
}
68
+
69
+
returnade_set_args(L, "t", &table);
70
+
}
71
+
72
+
ADE_FUNC(hasCustomData, l_Persona, nullptr, "Detects whether the persona has any custom data", "boolean", "true if the persona's custom_data is not empty, false otherwise. Nil if an error occurs.")
73
+
{
74
+
int idx = -1;
75
+
76
+
if (!ade_get_args(L, "o", l_Persona.Get(&idx)))
77
+
returnADE_RETURN_NIL;
78
+
79
+
if (!SCP_vector_inbounds(Personas, idx))
80
+
returnADE_RETURN_NIL;
81
+
82
+
bool result = !Personas[idx].custom_data.empty();
83
+
returnade_set_args(L, "b", result);
84
+
}
85
+
86
+
ADE_FUNC(isValid, l_Persona, nullptr, "Detect if the handle is valid", "boolean", "true if valid, false otherwise")
0 commit comments