Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/CLI/src/Flags.cpp
2725 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#include "Luau/Common.h"
3
#include "Luau/ExperimentalFlags.h"
4
5
#include <string_view>
6
7
#include <stdio.h>
8
#include <string.h>
9
10
static void setLuauFlag(std::string_view name, bool state)
11
{
12
for (Luau::FValue<bool>* flag = Luau::FValue<bool>::list; flag; flag = flag->next)
13
{
14
if (name == flag->name)
15
{
16
flag->value = state;
17
return;
18
}
19
}
20
21
fprintf(stderr, "Warning: unrecognized flag '%.*s'.\n", int(name.length()), name.data());
22
}
23
24
static void setLuauFlags(bool state)
25
{
26
for (Luau::FValue<bool>* flag = Luau::FValue<bool>::list; flag; flag = flag->next)
27
if (strncmp(flag->name, "Luau", 4) == 0)
28
flag->value = state;
29
}
30
31
void setLuauFlagsDefault()
32
{
33
for (Luau::FValue<bool>* flag = Luau::FValue<bool>::list; flag; flag = flag->next)
34
if (strncmp(flag->name, "Luau", 4) == 0 && !Luau::isAnalysisFlagExperimental(flag->name))
35
flag->value = true;
36
}
37
38
void setLuauFlags(const char* list)
39
{
40
std::string_view rest = list;
41
42
while (!rest.empty())
43
{
44
size_t ending = rest.find(",");
45
std::string_view element = rest.substr(0, ending);
46
47
if (size_t separator = element.find('='); separator != std::string_view::npos)
48
{
49
std::string_view key = element.substr(0, separator);
50
std::string_view value = element.substr(separator + 1);
51
52
if (value == "true" || value == "True")
53
setLuauFlag(key, true);
54
else if (value == "false" || value == "False")
55
setLuauFlag(key, false);
56
else
57
fprintf(
58
stderr, "Warning: unrecognized value '%.*s' for flag '%.*s'.\n", int(value.length()), value.data(), int(key.length()), key.data()
59
);
60
}
61
else
62
{
63
if (element == "true" || element == "True")
64
setLuauFlags(true);
65
else if (element == "false" || element == "False")
66
setLuauFlags(false);
67
else
68
setLuauFlag(element, true);
69
}
70
71
if (ending != std::string_view::npos)
72
rest.remove_prefix(ending + 1);
73
else
74
break;
75
}
76
}
77
78