MCPcopy Create free account
hub / github.com/InoriRus/Kyty / run_script

Function run_script

source/KytyScripts.cpp:60–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58}
59
60static void run_script(const String& lua_file_name, const StringList& args)
61{
62 RunString(U"arg = {}");
63 FOR (i, args)
64 {
65 if (i >= 2)
66 {
67 RunString(String::FromPrintf("arg[%d] = '%s'", i - 1, args.At(i).C_Str()));
68 }
69 }
70
71 bool is_file = true;
72 String statement;
73
74 if (lua_file_name.StartsWith(U'{') && lua_file_name.EndsWith(U'}'))
75 {
76 statement = lua_file_name.Mid(1, lua_file_name.Size() - 2);
77 is_file = false;
78 }
79
80 ScriptError err = is_file ? RunFile(lua_file_name) : RunString(statement);
81
82 if (err != ScriptError::Ok)
83 {
84 printf("can't run file %s\n", lua_file_name.utf8_str().GetData());
85 switch (err)
86 {
87 case ScriptError::FileError: printf("file error\n"); break;
88 case ScriptError::SyntaxError: printf("syntax error:\n%s\n", GetErrMsg().C_Str()); break;
89 case ScriptError::RunError: printf("run error:\n%s\n", GetErrMsg().C_Str()); break;
90
91 case ScriptError::UnknownError:
92 default: printf("unknown error\n");
93 }
94 }
95}
96
97int main(int argc, char* argv[])
98{

Callers 1

mainFunction · 0.85

Calls 9

RunStringFunction · 0.85
RunFileFunction · 0.85
printfFunction · 0.85
utf8_strMethod · 0.80
StartsWithMethod · 0.45
EndsWithMethod · 0.45
MidMethod · 0.45
SizeMethod · 0.45
GetDataMethod · 0.45

Tested by

no test coverage detected