| 489 | |
| 490 | |
| 491 | bool LoadScript(std::string const & script, std::string const & name = "") |
| 492 | { |
| 493 | /* Load the file containing the script we are going to run */ |
| 494 | int status = luaL_loadbufferx(state_, script.c_str(), script.size(), name.c_str(), "text"); |
| 495 | if (status != LUA_OK) { |
| 496 | OsiError("Failed to parse script: " << lua_tostring(state_, -1)); |
| 497 | lua_pop(state_, 1); /* pop error message from the stack */ |
| 498 | return false; |
| 499 | } |
| 500 | |
| 501 | /* Ask Lua to run our little script */ |
| 502 | status = lua_pcall(state_, 0, LUA_MULTRET, 0); |
| 503 | if (status != LUA_OK) { |
| 504 | OsiError("Failed to execute script: " << lua_tostring(state_, -1)); |
| 505 | lua_pop(state_, 1); // pop error message from the stack |
| 506 | return false; |
| 507 | } |
| 508 | |
| 509 | return true; |
| 510 | } |
| 511 | |
| 512 | void Call(char const * func, char const * arg) |
| 513 | { |