Rev 1642 | Rev 1647 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1642 | Rev 1644 | ||
|---|---|---|---|
| Line 181... | Line 181... | ||
| 181 | return true; |
181 | return true; |
| 182 | } |
182 | } |
| 183 | 183 | ||
| 184 | bool Manager::LoadScript(std::string scriptname) |
184 | bool Manager::LoadScript(std::string scriptname) |
| 185 | { |
185 | { |
| - | 186 | for (unsigned int n = 0; n < this->loaded_scripts_.size(); n++) |
|
| - | 187 | { |
|
| - | 188 | if (this->loaded_scripts_[n] == scriptname) |
|
| - | 189 | { |
|
| - | 190 | LOG.Info(scriptname + " is already loaded."); |
|
| - | 191 | return true; |
|
| - | 192 | } |
|
| - | 193 | } |
|
| - | 194 | ||
| 186 | std::string path = this->script_path_ + scriptname; |
195 | std::string path = this->script_path_ + scriptname; |
| 187 | std::ifstream file(path.data()); |
196 | std::ifstream file(path.data()); |
| 188 | 197 | ||
| 189 | if (!file.is_open()) |
198 | if (!file.is_open()) |
| 190 | { |
199 | { |
| Line 192... | Line 201... | ||
| 192 | LOG.Warning("Could not load " + scriptname + "."); |
201 | LOG.Warning("Could not load " + scriptname + "."); |
| 193 | return false; |
202 | return false; |
| 194 | } |
203 | } |
| 195 | 204 | ||
| 196 | std::string code = ""; |
205 | std::string code = ""; |
| 197 | std::string line; |
206 | std::string line; |
| 198 | 207 | ||
| 199 | while (!file.eof()) |
208 | while (!file.eof()) |
| 200 | { |
209 | { |
| 201 | std::getline(file, line); |
210 | std::getline(file, line); |
| 202 | 211 | ||
| 203 | if (file.eof()) |
212 | if (file.eof()) |
| 204 | { |
213 | { |
| 205 | break; |
214 | break; |
| 206 | } |
215 | } |
| 207 | 216 | ||
| 208 | code += line + "\n"; |
217 | code += line + "\n"; |
| 209 | } |
218 | } |
| 210 | 219 | ||
| 211 | code += "\n"; |
220 | code += "\n"; |
| 212 | 221 | ||
| 213 | file.close(); |
222 | file.close(); |
| 214 | 223 | ||
| 215 | v8::Context::Scope context_scope(this->context_); |
224 | v8::Context::Scope context_scope(this->context_); |
| 216 | 225 | ||
| Line 218... | Line 227... | ||
| 218 | 227 | ||
| 219 | v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New(code.data(), code.length()), |
228 | v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New(code.data(), code.length()), |
| 220 | v8::String::New(scriptname.data(), scriptname.length())); |
229 | v8::String::New(scriptname.data(), scriptname.length())); |
| 221 | 230 | ||
| 222 | if (script.IsEmpty()) |
231 | if (script.IsEmpty()) |
| 223 | { |
232 | { |
| 224 | LOG.Error(this->FormatException(try_catch)); |
233 | LOG.Error(this->FormatException(try_catch)); |
| 225 | return false; |
234 | return false; |
| 226 | } |
235 | } |
| 227 | else |
236 | else |
| 228 | { |
237 | { |
| 229 | Value result = script->Run(); |
238 | Value result = script->Run(); |
| 230 | 239 | ||
| 231 | if (result.IsEmpty()) |
240 | if (result.IsEmpty()) |
| 232 | { |
241 | { |
| 233 | LOG.Error(this->FormatException(try_catch)); |
242 | LOG.Error(this->FormatException(try_catch)); |
| 234 | return false; |
243 | return false; |
| 235 | } |
244 | } |
| 236 | } |
245 | } |
| - | 246 | ||
| - | 247 | this->loaded_scripts_.push_back(scriptname); |
|
| 237 | 248 | ||
| 238 | LOG.Info("Loaded " + scriptname + " successfully."); |
249 | LOG.Info("Loaded " + scriptname + " successfully."); |
| 239 | return true; |
250 | return true; |
| 240 | } |
251 | } |
| 241 | 252 | ||