MCPcopy Create free account
hub / github.com/CytopiaTeam/Cytopia / LoadScriptSection

Method LoadScriptSection

external/as_add_on/scriptbuilder/scriptbuilder.cpp:173–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171}
172
173int CScriptBuilder::LoadScriptSection(const char *filename)
174{
175 // Open the script file
176 string scriptFile = filename;
177#if _MSC_VER >= 1500 && !defined(__S3E__)
178 FILE *f = 0;
179 fopen_s(&f, scriptFile.c_str(), "rb");
180#else
181 FILE *f = fopen(scriptFile.c_str(), "rb");
182#endif
183 if( f == 0 )
184 {
185 // Write a message to the engine's message callback
186 string msg = "Failed to open script file '" + GetAbsolutePath(scriptFile) + "'";
187 engine->WriteMessage(filename, 0, 0, asMSGTYPE_ERROR, msg.c_str());
188
189 // TODO: Write the file where this one was included from
190
191 return -1;
192 }
193
194 // Determine size of the file
195 fseek(f, 0, SEEK_END);
196 int len = ftell(f);
197 fseek(f, 0, SEEK_SET);
198
199 // On Win32 it is possible to do the following instead
200 // int len = _filelength(_fileno(f));
201
202 // Read the entire file
203 string code;
204 size_t c = 0;
205 if( len > 0 )
206 {
207 code.resize(len);
208 c = fread(&code[0], len, 1, f);
209 }
210
211 fclose(f);
212
213 if( c == 0 && len > 0 )
214 {
215 // Write a message to the engine's message callback
216 string msg = "Failed to load script file '" + GetAbsolutePath(scriptFile) + "'";
217 engine->WriteMessage(filename, 0, 0, asMSGTYPE_ERROR, msg.c_str());
218 return -1;
219 }
220
221 // Process the script section even if it is zero length so that the name is registered
222 return ProcessScriptSection(code.c_str(), (unsigned int)(code.length()), filename, 0);
223}
224
225int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length, const char *sectionname, int lineOffset)
226{

Callers

nothing calls this directly

Calls 2

GetAbsolutePathFunction · 0.85
lengthMethod · 0.80

Tested by

no test coverage detected