lua_environment.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /*
  2. * Copyright (c) 2012-2023 Daniele Bartolini et al.
  3. * SPDX-License-Identifier: MIT
  4. */
  5. #include "config.h"
  6. #include "core/error/error.h"
  7. #include "core/json/json_object.inl"
  8. #include "core/json/sjson.h"
  9. #include "core/memory/temp_allocator.inl"
  10. #include "core/strings/dynamic_string.inl"
  11. #include "core/strings/string_stream.inl"
  12. #include "device/device.h"
  13. #include "device/log.h"
  14. #include "lua/lua_environment.h"
  15. #include "lua/lua_stack.inl"
  16. #include "resource/lua_resource.h"
  17. #include "resource/resource_manager.h"
  18. #include <lua.hpp>
  19. #include <stdarg.h>
  20. LOG_SYSTEM(LUA, "lua")
  21. namespace crown
  22. {
  23. extern void load_api(LuaEnvironment &env);
  24. static int luaB_print(lua_State *L)
  25. {
  26. TempAllocator2048 ta;
  27. StringStream ss(ta);
  28. int n = lua_gettop(L); /* number of arguments */
  29. lua_getglobal(L, "tostring");
  30. for (int i = 1; i <= n; ++i) {
  31. const char *s;
  32. lua_pushvalue(L, -1); /* function to be called */
  33. lua_pushvalue(L, i); /* value to print */
  34. lua_call(L, 1, 1);
  35. s = lua_tostring(L, -1); /* get result */
  36. if (s == NULL)
  37. return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("print"));
  38. if (i > 1)
  39. ss << "\t";
  40. ss << s;
  41. lua_pop(L, 1); /* pop result */
  42. }
  43. logi(LUA, string_stream::c_str(ss));
  44. return 0;
  45. }
  46. static int msghandler(lua_State *L)
  47. {
  48. const char *msg = lua_tostring(L, 1);
  49. if (msg == NULL) { /* is error object not a string? */
  50. if (luaL_callmeta(L, 1, "__tostring") && /* does it have a metamethod */
  51. lua_type(L, -1) == LUA_TSTRING) /* that produces a string? */
  52. return 1; /* that is the message */
  53. else
  54. msg = lua_pushfstring(L, "(error object is a %s value)",
  55. luaL_typename(L, 1));
  56. }
  57. #if CROWN_USE_LUAJIT
  58. luaL_traceback(L, L, msg, 1); /* append a standard traceback */
  59. #else
  60. lua_pushstring(L, "No traceback");
  61. #endif
  62. return 1; /* return the traceback */
  63. }
  64. /*
  65. ** Prints (calling the Lua 'print' function) any values on the stack
  66. */
  67. static void l_print(lua_State *L)
  68. {
  69. int n = lua_gettop(L);
  70. if (n > 0) { /* any result to be printed? */
  71. luaL_checkstack(L, LUA_MINSTACK, "too many results to print");
  72. lua_getglobal(L, "print");
  73. lua_insert(L, 1);
  74. if (lua_pcall(L, n, 0, 0) != LUA_OK)
  75. loge(LUA, lua_pushfstring(L, "error calling 'print' (%s)", lua_tostring(L, -1)));
  76. }
  77. }
  78. /*
  79. ** Try to compile line on the stack as 'return <line>;'; on return, stack
  80. ** has either compiled chunk or original line (if compilation failed).
  81. */
  82. static int addreturn(lua_State *L)
  83. {
  84. const char *line = lua_tostring(L, -1); /* original line */
  85. const char *retline = lua_pushfstring(L, "return %s;", line);
  86. int status = luaL_loadbuffer(L, retline, strlen(retline), "=stdin");
  87. if (status == LUA_OK)
  88. lua_remove(L, -2); /* remove modified line */
  89. else
  90. lua_pop(L, 2); /* pop result from 'luaL_loadbuffer' and modified line */
  91. return status;
  92. }
  93. /*
  94. ** Read a line and try to load (compile) it first as an expression (by
  95. ** adding "return " in front of it) and second as a statement. Return
  96. ** the final status of load/call with the resulting function (if any)
  97. ** in the top of the stack.
  98. */
  99. static int loadline(lua_State *L)
  100. {
  101. int status;
  102. if ((status = addreturn(L)) != LUA_OK) { /* 'return ...' did not work? */
  103. // status = multiline(L); /* try as command, maybe with continuation lines */
  104. size_t len;
  105. const char *line = lua_tolstring(L, 1, &len); /* get what it has */
  106. status = luaL_loadbuffer(L, line, len, "=stdin"); /* try it */
  107. }
  108. lua_remove(L, 1); /* remove line from the stack */
  109. lua_assert(lua_gettop(L) == 1);
  110. return status;
  111. }
  112. /*
  113. ** Check whether 'status' is not OK and, if so, prints the error
  114. ** message on the top of the stack. It assumes that the error object
  115. ** is a string, as it was either generated by Lua or by 'msghandler'.
  116. */
  117. int report(lua_State *L, int status)
  118. {
  119. if (status != LUA_OK) {
  120. const char *msg = lua_tostring(L, -1);
  121. loge(LUA, msg);
  122. lua_pop(L, 1); /* remove message */
  123. }
  124. return status;
  125. }
  126. static int loader(lua_State *L)
  127. {
  128. LuaStack stack(L);
  129. int status;
  130. const LuaResource *lr = (LuaResource *)device()->_resource_manager->get(RESOURCE_TYPE_SCRIPT, stack.get_resource_name(1));
  131. status = luaL_loadbuffer(L, lua_resource::program(lr), lr->size, "");
  132. if (status != LUA_OK) {
  133. report(L, status);
  134. device()->pause();
  135. }
  136. return 1;
  137. }
  138. #if CROWN_DEBUG
  139. static int require_internal(lua_State *L)
  140. {
  141. const char *module_name = lua_tostring(L, 1);
  142. bool already_loaded = false;
  143. lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
  144. lua_getfield(L, -1, module_name);
  145. already_loaded = lua_toboolean(L, -1);
  146. lua_pop(L, 2);
  147. lua_getglobal(L, "original_require");
  148. lua_pushvalue(L, -2);
  149. lua_remove(L, -3);
  150. lua_call(L, 1, 1);
  151. lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
  152. lua_getfield(L, 2, module_name);
  153. if (lua_toboolean(L, -1) && !already_loaded) {
  154. lua_pop(L, 2);
  155. lua_getglobal(L, "package");
  156. lua_getfield(L, -1, "load_order");
  157. lua_pushstring(L, module_name);
  158. lua_rawseti(L, -2, int(lua_objlen(L, -2) + 1));
  159. lua_pop(L, 2); // Pop "package.load_order" and "package"
  160. }
  161. return 1;
  162. }
  163. #endif // if CROWN_DEBUG
  164. LuaEnvironment::LuaEnvironment()
  165. : L(NULL)
  166. , _num_vec3(0)
  167. , _num_quat(0)
  168. , _num_mat4(0)
  169. #if CROWN_DEBUG
  170. , _vec3_marker(0)
  171. , _quat_marker(0)
  172. , _mat4_marker(0)
  173. , _random(0)
  174. #endif
  175. {
  176. #if CROWN_DEBUG
  177. // Initialize temporaries markers with random values.
  178. _random._seed = (s32)guid::new_guid().data1;
  179. reset_temporaries();
  180. #endif
  181. L = luaL_newstate();
  182. CE_ASSERT(L, "Unable to create lua state");
  183. }
  184. LuaEnvironment::~LuaEnvironment()
  185. {
  186. lua_close(L);
  187. }
  188. void LuaEnvironment::load_libs()
  189. {
  190. lua_gc(L, LUA_GCSTOP, 0);
  191. // Open default libraries
  192. lua_pushcfunction(L, luaopen_base);
  193. lua_pushstring(L, "");
  194. lua_call(L, 1, 0);
  195. lua_pushcfunction(L, luaopen_package);
  196. lua_pushstring(L, LUA_LOADLIBNAME);
  197. lua_call(L, 1, 0);
  198. lua_pushcfunction(L, luaopen_table);
  199. lua_pushstring(L, LUA_TABLIBNAME);
  200. lua_call(L, 1, 0);
  201. lua_pushcfunction(L, luaopen_string);
  202. lua_pushstring(L, LUA_STRLIBNAME);
  203. lua_call(L, 1, 0);
  204. lua_pushcfunction(L, luaopen_math);
  205. lua_pushstring(L, LUA_MATHLIBNAME);
  206. lua_call(L, 1, 0);
  207. lua_pushcfunction(L, luaopen_debug);
  208. lua_pushstring(L, LUA_DBLIBNAME);
  209. lua_call(L, 1, 0);
  210. #if CROWN_USE_LUAJIT
  211. lua_pushcfunction(L, luaopen_bit);
  212. lua_pushstring(L, LUA_BITLIBNAME);
  213. lua_call(L, 1, 0);
  214. lua_pushcfunction(L, luaopen_jit);
  215. lua_pushstring(L, LUA_JITLIBNAME);
  216. lua_call(L, 1, 0);
  217. #endif
  218. // Override print to redirect output to logging system
  219. add_module_function("_G", "print", luaB_print);
  220. // Register crown libraries
  221. load_api(*this);
  222. // Register custom loader
  223. lua_getglobal(L, "package");
  224. lua_getfield(L, -1, "loaders");
  225. lua_pushcfunction(L, loader);
  226. lua_rawseti(L, -2, 1); // package.loaders[1] = loader
  227. lua_pushnil(L);
  228. lua_rawseti(L, -2, 2); // package.loaders[2] = nil
  229. lua_pushnil(L);
  230. lua_rawseti(L, -2, 3); // package.loaders[3] = nil
  231. lua_pushnil(L);
  232. lua_rawseti(L, -2, 4); // package.loaders[4] = nil
  233. lua_pop(L, 1); // pop "package.loaders"
  234. #if CROWN_DEBUG
  235. // Create new empty table to store package load order
  236. lua_newtable(L);
  237. lua_setfield(L, -2, "load_order"); // package.load_order = {}
  238. // Override require() to keep track of libraries' load order
  239. lua_getglobal(L, "require");
  240. lua_setglobal(L, "original_require");
  241. lua_pushcclosure(L, require_internal, 0); // pass original require() to new require as upvalue
  242. lua_setglobal(L, "require");
  243. #endif
  244. lua_pop(L, 1); // pop "package"
  245. // Create metatable for lightuserdata
  246. lua_pushlightuserdata(L, 0);
  247. lua_getfield(L, LUA_REGISTRYINDEX, "Lightuserdata_mt");
  248. lua_setmetatable(L, -2);
  249. lua_pop(L, 1);
  250. // Ensure stack is clean
  251. CE_ASSERT(lua_gettop(L) == 0, "Stack not clean");
  252. lua_gc(L, LUA_GCRESTART, 0);
  253. }
  254. void LuaEnvironment::do_file(const char *name)
  255. {
  256. int status;
  257. lua_getglobal(L, "dofile");
  258. lua_pushstring(L, name);
  259. status = this->call(1, 0);
  260. if (status != LUA_OK) {
  261. report(L, status);
  262. device()->pause();
  263. }
  264. CE_ASSERT(lua_gettop(L) == 0, "Stack not clean");
  265. }
  266. void LuaEnvironment::require(const char *name)
  267. {
  268. int status;
  269. lua_getglobal(L, "require");
  270. lua_pushstring(L, name);
  271. status = this->call(1, 0);
  272. if (status != LUA_OK) {
  273. report(L, status);
  274. device()->pause();
  275. }
  276. CE_ASSERT(lua_gettop(L) == 0, "Stack not clean");
  277. }
  278. LuaStack LuaEnvironment::execute(const LuaResource *lr, int nres)
  279. {
  280. LuaStack stack(L);
  281. int status;
  282. status = luaL_loadbuffer(L, lua_resource::program(lr), lr->size, "<unknown>");
  283. if (status == LUA_OK)
  284. status = this->call(0, nres);
  285. if (status != LUA_OK) {
  286. report(L, status);
  287. device()->pause();
  288. }
  289. return stack;
  290. }
  291. LuaStack LuaEnvironment::execute_string(const char *s)
  292. {
  293. LuaStack stack(L);
  294. int status;
  295. status = luaL_loadstring(L, s);
  296. if (status == LUA_OK)
  297. status = this->call(0, 0);
  298. if (status != LUA_OK) {
  299. report(L, status);
  300. device()->pause();
  301. }
  302. CE_ASSERT(lua_gettop(L) == 0, "Stack not clean");
  303. return stack;
  304. }
  305. void LuaEnvironment::add_module_function(const char *module, const char *name, const lua_CFunction func)
  306. {
  307. luaL_Reg entry[2];
  308. entry[0].name = name;
  309. entry[0].func = func;
  310. entry[1].name = NULL;
  311. entry[1].func = NULL;
  312. luaL_register(L, module, entry);
  313. lua_pop(L, 1);
  314. }
  315. void LuaEnvironment::add_module_function(const char *module, const char *name, const char *func)
  316. {
  317. // Create module if it does not exist
  318. luaL_Reg entry;
  319. entry.name = NULL;
  320. entry.func = NULL;
  321. luaL_register(L, module, &entry);
  322. lua_pop(L, 1);
  323. lua_getglobal(L, module);
  324. lua_getglobal(L, func);
  325. lua_setfield(L, -2, name);
  326. lua_setglobal(L, module);
  327. }
  328. void LuaEnvironment::add_module_metafunction(const char *module, const char *name, const lua_CFunction func)
  329. {
  330. // Create module if it does not exist
  331. luaL_Reg entry[2];
  332. entry[0].name = NULL;
  333. entry[0].func = NULL;
  334. luaL_register(L, module, entry);
  335. lua_pop(L, 1);
  336. luaL_newmetatable(L, module);
  337. if (func) {
  338. entry[0].name = name;
  339. entry[0].func = func;
  340. entry[1].name = NULL;
  341. entry[1].func = NULL;
  342. luaL_register(L, NULL, entry);
  343. } else {
  344. lua_pushstring(L, name);
  345. lua_pushvalue(L, -2);
  346. lua_settable(L, -3);
  347. }
  348. lua_getglobal(L, module);
  349. lua_pushvalue(L, -2);
  350. lua_setmetatable(L, -2);
  351. lua_pop(L, -1);
  352. }
  353. void LuaEnvironment::set_module_number(const char *module, const char *name, f64 value)
  354. {
  355. // Create module if it does not exist
  356. luaL_Reg entry;
  357. entry.name = NULL;
  358. entry.func = NULL;
  359. luaL_register(L, module, &entry);
  360. lua_pop(L, 1);
  361. lua_getglobal(L, module);
  362. lua_pushnumber(L, value);
  363. lua_setfield(L, -2, name);
  364. lua_pop(L, 1);
  365. }
  366. int LuaEnvironment::call(int narg, int nres)
  367. {
  368. int status;
  369. int base = lua_gettop(L) - narg; /* function index */
  370. lua_pushcfunction(L, msghandler); /* push message handler */
  371. lua_insert(L, base); /* put it under function and args */
  372. status = lua_pcall(L, narg, nres, base);
  373. lua_remove(L, base); /* remove message handler from the stack */
  374. return status;
  375. }
  376. void LuaEnvironment::call_global(const char *func, int narg, int nres)
  377. {
  378. int status;
  379. CE_ENSURE(NULL != func);
  380. lua_getglobal(L, func);
  381. lua_insert(L, 1); // Move func to the top of stack
  382. status = call(narg, nres);
  383. if (status != LUA_OK) {
  384. report(L, status);
  385. device()->pause();
  386. }
  387. CE_ASSERT(lua_gettop(L) == 0, "Stack not clean");
  388. }
  389. LuaStack LuaEnvironment::get_global(const char *global)
  390. {
  391. LuaStack stack(L);
  392. lua_getglobal(L, global);
  393. return stack;
  394. }
  395. Vector3 *LuaEnvironment::next_vector3(const Vector3 &v)
  396. {
  397. CE_ASSERT(_num_vec3 < LUA_MAX_VECTOR3, "Maximum number of Vector3 reached");
  398. Vector3 *vec3 = &(_vec3[_num_vec3++] = v);
  399. uintptr_t ptr = (uintptr_t)(void *)vec3;
  400. #if CROWN_DEBUG
  401. ptr |= _vec3_marker;
  402. #endif
  403. return (Vector3 *)ptr;
  404. }
  405. Quaternion *LuaEnvironment::next_quaternion(const Quaternion &q)
  406. {
  407. CE_ASSERT(_num_quat < LUA_MAX_QUATERNION, "Maximum number of Quaternion reached");
  408. Quaternion *quat = &(_quat[_num_quat++] = q);
  409. uintptr_t ptr = (uintptr_t)(void *)quat;
  410. #if CROWN_DEBUG
  411. ptr |= _quat_marker;
  412. #endif
  413. return (Quaternion *)ptr;
  414. }
  415. Matrix4x4 *LuaEnvironment::next_matrix4x4(const Matrix4x4 &m)
  416. {
  417. CE_ASSERT(_num_mat4 < LUA_MAX_MATRIX4X4, "Maximum number of Matrix4x4 reached");
  418. Matrix4x4 *mat4 = &(_mat4[_num_mat4++] = m);
  419. uintptr_t ptr = (uintptr_t)(void *)mat4;
  420. #if CROWN_DEBUG
  421. ptr |= _mat4_marker;
  422. #endif
  423. return (Matrix4x4 *)ptr;
  424. }
  425. bool LuaEnvironment::is_vector3(const void *ptr)
  426. {
  427. return ptr >= &_vec3[0]
  428. && ptr <= &_vec3[LUA_MAX_VECTOR3 - 1];
  429. }
  430. bool LuaEnvironment::is_quaternion(const void *ptr)
  431. {
  432. return ptr >= &_quat[0]
  433. && ptr <= &_quat[LUA_MAX_QUATERNION - 1];
  434. }
  435. bool LuaEnvironment::is_matrix4x4(const void *ptr)
  436. {
  437. return ptr >= &_mat4[0]
  438. && ptr <= &_mat4[LUA_MAX_MATRIX4X4 - 1];
  439. }
  440. #if CROWN_DEBUG
  441. Vector3 *LuaEnvironment::check_valid(const Vector3 *ptr)
  442. {
  443. LUA_ASSERT(((uintptr_t)ptr & LUA_VECTOR3_MARKER_MASK) >> LUA_VECTOR3_MARKER_SHIFT == _vec3_marker
  444. , LuaStack(L)
  445. , "Stale Vector3 ptr: %p, expected marker: %p"
  446. , ptr
  447. , _vec3_marker
  448. );
  449. return (Vector3 *)(uintptr_t(ptr) & ~LUA_VECTOR3_MARKER_MASK);
  450. }
  451. Quaternion *LuaEnvironment::check_valid(const Quaternion *ptr)
  452. {
  453. LUA_ASSERT(((uintptr_t)ptr & LUA_QUATERNION_MARKER_MASK) >> LUA_QUATERNION_MARKER_SHIFT == _quat_marker
  454. , LuaStack(L)
  455. , "Stale Quaternion ptr: %p, expected marker: %p"
  456. , ptr
  457. , _quat_marker
  458. );
  459. return (Quaternion *)(uintptr_t(ptr) & ~LUA_QUATERNION_MARKER_MASK);
  460. }
  461. Matrix4x4 *LuaEnvironment::check_valid(const Matrix4x4 *ptr)
  462. {
  463. LUA_ASSERT(((uintptr_t)ptr & LUA_MATRIX4X4_MARKER_MASK) >> LUA_MATRIX4X4_MARKER_SHIFT == _mat4_marker
  464. , LuaStack(L)
  465. , "Stale Matrix4x4 ptr: %p, expected marker: %p"
  466. , ptr
  467. , _mat4_marker
  468. );
  469. return (Matrix4x4 *)(uintptr_t(ptr) & ~LUA_MATRIX4X4_MARKER_MASK);
  470. }
  471. #endif // if CROWN_DEBUG
  472. void LuaEnvironment::reload()
  473. {
  474. lua_getglobal(L, "package");
  475. lua_getfield(L, -1, "load_order");
  476. for (size_t i = 1, n = lua_objlen(L, -1); i < n + 1; ++i) {
  477. lua_rawgeti(L, -1, (int)i);
  478. logi(LUA, "reloading: %s", lua_tostring(L, -1));
  479. LuaStack stack(L);
  480. StringId64 name = stack.get_resource_name(-1);
  481. this->execute((const LuaResource *)device()->_resource_manager->get(RESOURCE_TYPE_SCRIPT, name), 0);
  482. lua_pop(L, 1);
  483. }
  484. lua_pop(L, 2);
  485. }
  486. void LuaEnvironment::temp_count(u32 &num_vec3, u32 &num_quat, u32 &num_mat4)
  487. {
  488. num_vec3 = _num_vec3;
  489. num_quat = _num_quat;
  490. num_mat4 = _num_mat4;
  491. }
  492. void LuaEnvironment::set_temp_count(u32 num_vec3, u32 num_quat, u32 num_mat4)
  493. {
  494. _num_vec3 = num_vec3;
  495. _num_quat = num_quat;
  496. _num_mat4 = num_mat4;
  497. }
  498. void LuaEnvironment::reset_temporaries()
  499. {
  500. _num_vec3 = 0;
  501. _num_quat = 0;
  502. _num_mat4 = 0;
  503. #if CROWN_DEBUG
  504. _vec3_marker = (uintptr_t)_random.integer(1 + LUA_VECTOR3_MARKER_MASK);
  505. _quat_marker = (uintptr_t)_random.integer(1 + LUA_QUATERNION_MARKER_MASK);
  506. _mat4_marker = (uintptr_t)_random.integer(1 + LUA_MATRIX4X4_MARKER_MASK);
  507. #endif
  508. }
  509. static void console_command_script(ConsoleServer & /*cs*/, u32 /*client_id*/, const char *json, void *user_data)
  510. {
  511. TempAllocator4096 ta;
  512. JsonObject obj(ta);
  513. DynamicString script(ta);
  514. sjson::parse(obj, json);
  515. sjson::parse_string(script, obj["script"]);
  516. ((LuaEnvironment *)user_data)->execute_string(script.c_str());
  517. }
  518. static void do_REPL(LuaEnvironment *env, const char *lua)
  519. {
  520. lua_State *L = env->L;
  521. int status;
  522. lua_settop(L, 0);
  523. lua_pushstring(L, lua);
  524. if ((status = loadline(L)) != -1) { // This is never -1
  525. if (status == LUA_OK) {
  526. status = env->call(0, LUA_MULTRET);
  527. }
  528. if (status == LUA_OK)
  529. l_print(L);
  530. else
  531. report(L, status);
  532. }
  533. lua_settop(L, 0); /* clear stack */
  534. return;
  535. }
  536. static void console_command_REPL(ConsoleServer & /*cs*/, u32 /*client_id*/, const char *json, void *user_data)
  537. {
  538. TempAllocator4096 ta;
  539. JsonObject obj(ta);
  540. DynamicString script(ta);
  541. sjson::parse(obj, json);
  542. sjson::parse_string(script, obj["repl"]);
  543. do_REPL((LuaEnvironment *)user_data, script.c_str());
  544. }
  545. void LuaEnvironment::register_console_commands(ConsoleServer &cs)
  546. {
  547. cs.register_message_type("script", console_command_script, this);
  548. cs.register_message_type("repl", console_command_REPL, this);
  549. }
  550. } // namespace crown