Simutrans-Squirrel-API  r11919
api_control.cc
Go to the documentation of this file.
1 /*
2  * This file is part of the Simutrans project under the Artistic License.
3  * (see LICENSE.txt)
4  */
5 
6 #include "api.h"
7 
10 #include "../api_function.h"
11 #include "../api_class.h"
12 #include "../script.h"
13 #include "../../../squirrel/sq_extensions.h"
14 #include "../../tool/simtool.h"
15 
16 namespace script_api {
17 
18  bool pause_game()
19  {
20  tool_pause_t t;
21  if (!t.is_selected()) {
22  t.init(NULL);
23  }
24  return t.is_selected();
25  }
26 
27  bool is_game_paused()
28  {
29  tool_pause_t t;
30  return t.is_selected();
31  }
32 };
33 
34 using namespace script_api;
35 
36 SQInteger sleep(HSQUIRRELVM vm)
37 {
38  if (const char* blocker = sq_get_suspend_blocker(vm)) {
39  return sq_raise_error(vm, "Cannot call sleep from within `%s'.", blocker);
40  }
41  return sq_suspendvm(vm);
42 }
43 
44 SQInteger set_pause_on_error(HSQUIRRELVM vm)
45 {
46  if (script_vm_t *script = (script_vm_t*)sq_getforeignptr(vm)) {
47  bool poe = param<bool>::get(vm, 2);
48  script->pause_on_error = poe;
49  }
50  return SQ_OK;
51 }
52 
53 
54 
55 void export_control(HSQUIRRELVM vm)
56 {
57  // in global scope
58 
65  register_function(vm, sleep, "sleep", 1, ".");
66 
70  register_function<int(*)()>(vm, sq_get_ops_total, "get_ops_total");
71 
75  register_function<int(*)()>(vm, sq_get_ops_remaing, "get_ops_remaining");
76 
77 
78  begin_class(vm, "debug");
83  STATIC register_method(vm, &pause_game, "pause", false, true);
90  STATIC register_method(vm, &is_game_paused, "is_paused", false, true);
91 
97  STATIC register_function<void(*)(bool)>(vm, set_pause_on_error, "set_pause_on_error", true);
98 
99  end_class(vm);
100 }
void sleep()