lua_stack.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. /*
  2. * Copyright (c) 2012-2018 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/dbartolini/crown/blob/master/LICENSE
  4. */
  5. #pragma once
  6. #include "config.h"
  7. #include "core/math/types.h"
  8. #include "core/strings/string_id.h"
  9. #include "core/types.h"
  10. #include "resource/types.h"
  11. #include "world/types.h"
  12. #include <lua.hpp>
  13. #ifndef LUA_OK
  14. #define LUA_OK 0
  15. #endif
  16. #if CROWN_DEBUG
  17. #define LUA_ASSERT(condition, stack, msg, ...) \
  18. do \
  19. { \
  20. if (CE_UNLIKELY(!(condition))) \
  21. { \
  22. stack.push_fstring("Assertion failed: %s\n " msg "\n" \
  23. , # condition \
  24. , ## __VA_ARGS__ \
  25. ); \
  26. lua_error(stack.L); \
  27. CE_UNREACHABLE(); \
  28. } \
  29. } \
  30. while (0)
  31. #else
  32. #define LUA_ASSERT(...) CE_NOOP()
  33. #endif // CROWN_DEBUG
  34. #define LIGHTDATA_TYPE_MASK uintptr_t(0x3)
  35. #define LIGHTDATA_TYPE_SHIFT uintptr_t(0)
  36. #define LIGHTDATA_POINTER_MARKER uintptr_t(0)
  37. #define LIGHTDATA_UNIT_MARKER uintptr_t(1)
  38. #define LIGHTDATA_UNIT_ID_MASK uintptr_t(0xfffffffc)
  39. #define LIGHTDATA_UNIT_ID_SHIFT uintptr_t(2)
  40. #define LUA_VECTOR3_MARKER_MASK uintptr_t(0x03)
  41. #define LUA_VECTOR3_MARKER_SHIFT uintptr_t(0)
  42. #define LUA_QUATERNION_MARKER_MASK uintptr_t(0x0f)
  43. #define LUA_QUATERNION_MARKER_SHIFT uintptr_t(0)
  44. #define LUA_MATRIX4X4_MARKER_MASK uintptr_t(0x3f)
  45. #define LUA_MATRIX4X4_MARKER_SHIFT uintptr_t(0)
  46. namespace crown
  47. {
  48. /// Wrapper to manipulate Lua stack.
  49. ///
  50. /// @ingroup Lua
  51. struct LuaStack
  52. {
  53. lua_State* L;
  54. LuaStack(lua_State* L)
  55. : L(L)
  56. {
  57. }
  58. /// Returns the number of elements in the stack.
  59. /// When called inside a function, it can be used to count
  60. /// the number of arguments passed to the function itself.
  61. int num_args()
  62. {
  63. return lua_gettop(L);
  64. }
  65. /// Removes the element at the given valid index, shifting down the elements
  66. /// above this index to fill the gap. Cannot be called with a pseudo-index,
  67. /// because a pseudo-index is not an actual stack position.
  68. void remove(int i)
  69. {
  70. lua_remove(L, i);
  71. }
  72. /// Pops @a n elements from the stack.
  73. void pop(int n)
  74. {
  75. lua_pop(L, n);
  76. }
  77. bool is_nil(int i)
  78. {
  79. return lua_isnil(L, i) == 1;
  80. }
  81. bool is_bool(int i)
  82. {
  83. return lua_isboolean(L, i) == 1;
  84. }
  85. bool is_number(int i)
  86. {
  87. return lua_isnumber(L, i) == 1;
  88. }
  89. bool is_string(int i)
  90. {
  91. return lua_isstring(L, i) == 1;
  92. }
  93. bool is_pointer(int i)
  94. {
  95. return lua_islightuserdata(L, i) == 1
  96. && ((uintptr_t)lua_touserdata(L, i) & LIGHTDATA_TYPE_MASK) == LIGHTDATA_POINTER_MARKER;
  97. }
  98. bool is_function(int i)
  99. {
  100. return lua_isfunction(L, i) == 1;
  101. }
  102. bool is_table(int i)
  103. {
  104. return lua_istable(L, i) == 1;
  105. }
  106. bool is_vector3(int i);
  107. bool is_quaternion(int i);
  108. bool is_matrix4x4(int i);
  109. /// Wraps lua_type.
  110. int value_type(int i)
  111. {
  112. return lua_type(L, i);
  113. }
  114. bool get_bool(int i)
  115. {
  116. return lua_toboolean(L, i) == 1;
  117. }
  118. int get_int(int i)
  119. {
  120. #if CROWN_DEBUG
  121. return (int)luaL_checknumber(L, i);
  122. #else
  123. return (int)lua_tonumber(L, i);
  124. #endif
  125. }
  126. f32 get_float(int i)
  127. {
  128. #if CROWN_DEBUG
  129. return (f32)luaL_checknumber(L, i);
  130. #else
  131. return (f32)lua_tonumber(L, i);
  132. #endif
  133. }
  134. const char* get_string(int i)
  135. {
  136. #if CROWN_DEBUG
  137. return luaL_checkstring(L, i);
  138. #else
  139. return lua_tostring(L, i);
  140. #endif
  141. }
  142. void* get_pointer(int i)
  143. {
  144. #if CROWN_DEBUG
  145. if (CE_UNLIKELY(lua_isuserdata(L, i) == 0))
  146. {
  147. luaL_typerror(L, i, "userdata");
  148. CE_UNREACHABLE();
  149. }
  150. #endif
  151. void* p = lua_touserdata(L, i);
  152. CE_ENSURE(p != NULL); // NULL iff object is not userdata
  153. return p;
  154. }
  155. u32 get_id(int i)
  156. {
  157. #if CROWN_DEBUG
  158. return (u32)luaL_checknumber(L, i);
  159. #else
  160. return (u32)lua_tonumber(L, i);
  161. #endif
  162. }
  163. StringId32 get_string_id_32(int i)
  164. {
  165. return StringId32(get_string(i));
  166. }
  167. StringId64 get_string_id_64(int i)
  168. {
  169. return StringId64(get_string(i));
  170. }
  171. StringId64 get_resource_name(int i)
  172. {
  173. return get_string_id_64(i);
  174. }
  175. Gui* get_gui(int i)
  176. {
  177. Gui* p = (Gui*)get_pointer(i);
  178. #if CROWN_DEBUG
  179. check_type(i, p);
  180. #endif // CROWN_DEBUG
  181. return p;
  182. }
  183. DebugLine* get_debug_line(int i)
  184. {
  185. DebugLine* p = (DebugLine*)get_pointer(i);
  186. #if CROWN_DEBUG
  187. check_type(i, p);
  188. #endif // CROWN_DEBUG
  189. return p;
  190. }
  191. ResourcePackage* get_resource_package(int i)
  192. {
  193. ResourcePackage* p = (ResourcePackage*)get_pointer(i);
  194. #if CROWN_DEBUG
  195. check_type(i, p);
  196. #endif // CROWN_DEBUG
  197. return p;
  198. }
  199. World* get_world(int i)
  200. {
  201. World* p = (World*)get_pointer(i);
  202. #if CROWN_DEBUG
  203. check_type(i, p);
  204. #endif // CROWN_DEBUG
  205. return p;
  206. }
  207. SceneGraph* get_scene_graph(int i)
  208. {
  209. SceneGraph* p = (SceneGraph*)get_pointer(i);
  210. #if CROWN_DEBUG
  211. check_type(i, p);
  212. #endif // CROWN_DEBUG
  213. return p;
  214. }
  215. Level* get_level(int i)
  216. {
  217. Level* p = (Level*)get_pointer(i);
  218. #if CROWN_DEBUG
  219. check_type(i, p);
  220. #endif // CROWN_DEBUG
  221. return p;
  222. }
  223. RenderWorld* get_render_world(int i)
  224. {
  225. RenderWorld* p = (RenderWorld*)get_pointer(i);
  226. #if CROWN_DEBUG
  227. check_type(i, p);
  228. #endif // CROWN_DEBUG
  229. return p;
  230. }
  231. PhysicsWorld* get_physics_world(int i)
  232. {
  233. PhysicsWorld* p = (PhysicsWorld*)get_pointer(i);
  234. #if CROWN_DEBUG
  235. check_type(i, p);
  236. #endif // CROWN_DEBUG
  237. return p;
  238. }
  239. SoundWorld* get_sound_world(int i)
  240. {
  241. SoundWorld* p = (SoundWorld*)get_pointer(i);
  242. #if CROWN_DEBUG
  243. check_type(i, p);
  244. #endif // CROWN_DEBUG
  245. return p;
  246. }
  247. ScriptWorld* get_script_world(int i)
  248. {
  249. ScriptWorld* p = (ScriptWorld*)get_pointer(i);
  250. #if CROWN_DEBUG
  251. check_type(i, p);
  252. #endif // CROWN_DEBUG
  253. return p;
  254. }
  255. AnimationStateMachine* get_animation_state_machine(int i)
  256. {
  257. AnimationStateMachine* p = (AnimationStateMachine*)get_pointer(i);
  258. #if CROWN_DEBUG
  259. check_type(i, p);
  260. #endif // CROWN_DEBUG
  261. return p;
  262. }
  263. UnitId get_unit(int i)
  264. {
  265. uintptr_t enc = (uintptr_t)get_pointer(i);
  266. #if CROWN_DEBUG
  267. if ((enc & LIGHTDATA_TYPE_MASK) != LIGHTDATA_UNIT_MARKER)
  268. {
  269. luaL_typerror(L, i, "UnitId");
  270. CE_UNREACHABLE();
  271. }
  272. #endif // CROWN_DEBUG
  273. UnitId id;
  274. id._idx = u32((enc & LIGHTDATA_UNIT_ID_MASK) >> LIGHTDATA_UNIT_ID_SHIFT);
  275. return id;
  276. }
  277. CameraInstance get_camera(int i)
  278. {
  279. CameraInstance inst = { get_id(i) };
  280. return inst;
  281. }
  282. TransformInstance get_transform(int i)
  283. {
  284. TransformInstance inst = { get_id(i) };
  285. return inst;
  286. }
  287. MeshInstance get_mesh_instance(int i)
  288. {
  289. MeshInstance inst = { get_id(i) };
  290. return inst;
  291. }
  292. SpriteInstance get_sprite_instance(int i)
  293. {
  294. SpriteInstance inst = { get_id(i) };
  295. return inst;
  296. }
  297. LightInstance get_light_instance(int i)
  298. {
  299. LightInstance inst = { get_id(i) };
  300. return inst;
  301. }
  302. Material* get_material(int i)
  303. {
  304. return (Material*)get_pointer(i);
  305. }
  306. ActorInstance get_actor(int i)
  307. {
  308. ActorInstance inst = { get_id(i) };
  309. return inst;
  310. }
  311. SoundInstanceId get_sound_instance_id(int i)
  312. {
  313. return get_id(i);
  314. }
  315. ScriptInstance get_script_instance(int i)
  316. {
  317. ScriptInstance inst = { get_id(i) };
  318. return inst;
  319. }
  320. Vector2 get_vector2(int i)
  321. {
  322. Vector3 v = get_vector3(i);
  323. Vector2 a;
  324. a.x = v.x;
  325. a.y = v.y;
  326. return a;
  327. }
  328. Vector3& get_vector3(int i)
  329. {
  330. #if CROWN_DEBUG
  331. return *check_temporary(i, (Vector3*)get_pointer(i));
  332. #else
  333. return *(Vector3*)get_pointer(i);
  334. #endif
  335. }
  336. Vector4 get_vector4(int i)
  337. {
  338. Quaternion q = get_quaternion(i);
  339. Vector4 a;
  340. a.x = q.x;
  341. a.y = q.y;
  342. a.z = q.z;
  343. a.w = q.w;
  344. return a;
  345. }
  346. Quaternion& get_quaternion(int i)
  347. {
  348. #if CROWN_DEBUG
  349. return *check_temporary(i, (Quaternion*)get_pointer(i));
  350. #else
  351. return *(Quaternion*)get_pointer(i);
  352. #endif
  353. }
  354. Matrix4x4& get_matrix4x4(int i)
  355. {
  356. #if CROWN_DEBUG
  357. return *check_temporary(i, (Matrix4x4*)get_pointer(i));
  358. #else
  359. return *(Matrix4x4*)get_pointer(i);
  360. #endif
  361. }
  362. Color4 get_color4(int i)
  363. {
  364. Quaternion q = get_quaternion(i);
  365. Color4 c;
  366. c.x = q.x;
  367. c.y = q.y;
  368. c.z = q.z;
  369. c.w = q.w;
  370. return c;
  371. }
  372. Vector2& get_vector2box(int i)
  373. {
  374. Vector2* v = (Vector2*)luaL_checkudata(L, i, "Vector2Box");
  375. return *v;
  376. }
  377. Vector3& get_vector3box(int i)
  378. {
  379. Vector3* v = (Vector3*)luaL_checkudata(L, i, "Vector3Box");
  380. return *v;
  381. }
  382. Quaternion& get_quaternionbox(int i)
  383. {
  384. Quaternion* q = (Quaternion*)luaL_checkudata(L, i, "QuaternionBox");
  385. return *q;
  386. }
  387. Matrix4x4& get_matrix4x4box(int i)
  388. {
  389. Matrix4x4* m = (Matrix4x4*)luaL_checkudata(L, i, "Matrix4x4Box");
  390. return *m;
  391. }
  392. void push_nil()
  393. {
  394. lua_pushnil(L);
  395. }
  396. void push_bool(bool value)
  397. {
  398. lua_pushboolean(L, value);
  399. }
  400. void push_int(int value)
  401. {
  402. lua_pushnumber(L, value);
  403. }
  404. void push_float(f32 value)
  405. {
  406. lua_pushnumber(L, value);
  407. }
  408. void push_string(const char* s)
  409. {
  410. lua_pushstring(L, s);
  411. }
  412. void push_fstring(const char* fmt, ...)
  413. {
  414. va_list vl;
  415. va_start(vl, fmt);
  416. lua_pushvfstring(L, fmt, vl);
  417. va_end(vl);
  418. }
  419. void push_lstring(const char* s, u32 len)
  420. {
  421. lua_pushlstring(L, s, len);
  422. }
  423. void push_string_id(StringId32 value)
  424. {
  425. lua_pushnumber(L, value._id);
  426. }
  427. void push_pointer(void* p)
  428. {
  429. CE_ENSURE(NULL != p);
  430. lua_pushlightuserdata(L, p);
  431. }
  432. void push_function(lua_CFunction f)
  433. {
  434. lua_pushcfunction(L, f);
  435. }
  436. void push_id(u32 value)
  437. {
  438. lua_pushnumber(L, value);
  439. }
  440. /// Pushes an empty table onto the stack.
  441. /// When you want to set keys on the table, you have to use LuaStack::push_key_begin()
  442. /// and LuaStack::push_key_end() as in the following example:
  443. ///
  444. /// LuaStack stack(L)
  445. /// stack.push_table()
  446. /// stack.push_key_begin("foo"); stack.push_foo(); stack.push_key_end()
  447. /// stack.push_key_begin("bar"); stack.push_bar(); stack.push_key_end()
  448. /// return 1;
  449. void push_table(int narr = 0, int nrec = 0)
  450. {
  451. lua_createtable(L, narr, nrec);
  452. }
  453. /// See Stack::push_table()
  454. void push_key_begin(const char* key)
  455. {
  456. lua_pushstring(L, key);
  457. }
  458. /// See Stack::push_table()
  459. void push_key_begin(int i)
  460. {
  461. lua_pushnumber(L, i);
  462. }
  463. /// See Stack::push_table()
  464. void push_key_end()
  465. {
  466. lua_settable(L, -3);
  467. }
  468. int next(int i)
  469. {
  470. return lua_next(L, i);
  471. }
  472. void push_gui(Gui* dg)
  473. {
  474. push_pointer(dg);
  475. }
  476. void push_debug_line(DebugLine* line)
  477. {
  478. push_pointer(line);
  479. }
  480. void push_resource_package(ResourcePackage* package)
  481. {
  482. push_pointer(package);
  483. }
  484. void push_world(World* world)
  485. {
  486. push_pointer(world);
  487. };
  488. void push_scene_graph(SceneGraph* sg)
  489. {
  490. push_pointer(sg);
  491. }
  492. void push_level(Level* level)
  493. {
  494. push_pointer(level);
  495. }
  496. void push_render_world(RenderWorld* world)
  497. {
  498. push_pointer(world);
  499. }
  500. void push_physics_world(PhysicsWorld* world)
  501. {
  502. push_pointer(world);
  503. }
  504. void push_sound_world(SoundWorld* world)
  505. {
  506. push_pointer(world);
  507. }
  508. void push_script_world(ScriptWorld* world)
  509. {
  510. push_pointer(world);
  511. }
  512. void push_animation_state_machine(AnimationStateMachine* sm)
  513. {
  514. push_pointer(sm);
  515. }
  516. void push_unit(UnitId id)
  517. {
  518. uintptr_t enc = (uintptr_t(id._idx) << LIGHTDATA_UNIT_ID_SHIFT) | LIGHTDATA_UNIT_MARKER;
  519. push_pointer((void*)enc);
  520. }
  521. void push_camera(CameraInstance i)
  522. {
  523. push_id(i.i);
  524. }
  525. void push_transform(TransformInstance i)
  526. {
  527. push_id(i.i);
  528. }
  529. void push_mesh_instance(MeshInstance i)
  530. {
  531. push_id(i.i);
  532. }
  533. void push_sprite_instance(SpriteInstance i)
  534. {
  535. push_id(i.i);
  536. }
  537. void push_light_instance(LightInstance i)
  538. {
  539. push_id(i.i);
  540. }
  541. void push_material(Material* material)
  542. {
  543. push_pointer(material);
  544. }
  545. void push_actor(ActorInstance i)
  546. {
  547. push_id(i.i);
  548. }
  549. void push_sound_instance_id(SoundInstanceId id)
  550. {
  551. push_id(id);
  552. }
  553. void push_script_instance(ScriptInstance i)
  554. {
  555. push_id(i.i);
  556. }
  557. void push_vector2(const Vector2& v);
  558. void push_vector3(const Vector3& v);
  559. void push_matrix4x4(const Matrix4x4& m);
  560. void push_quaternion(const Quaternion& q);
  561. void push_color4(const Color4& c);
  562. void push_vector2box(const Vector2& v)
  563. {
  564. Vector2* vec = (Vector2*)lua_newuserdata(L, sizeof(Vector2));
  565. luaL_getmetatable(L, "Vector2Box");
  566. lua_setmetatable(L, -2);
  567. *vec = v;
  568. }
  569. void push_vector3box(const Vector3& v)
  570. {
  571. Vector3* vec = (Vector3*)lua_newuserdata(L, sizeof(Vector3));
  572. luaL_getmetatable(L, "Vector3Box");
  573. lua_setmetatable(L, -2);
  574. *vec = v;
  575. }
  576. void push_quaternionbox(const Quaternion& q)
  577. {
  578. Quaternion* quat = (Quaternion*)lua_newuserdata(L, sizeof(Quaternion));
  579. luaL_getmetatable(L, "QuaternionBox");
  580. lua_setmetatable(L, -2);
  581. *quat = q;
  582. }
  583. void push_matrix4x4box(const Matrix4x4& m)
  584. {
  585. Matrix4x4* mat = (Matrix4x4*)lua_newuserdata(L, sizeof(Matrix4x4));
  586. luaL_getmetatable(L, "Matrix4x4Box");
  587. lua_setmetatable(L, -2);
  588. *mat = m;
  589. }
  590. void push_value(int i)
  591. {
  592. lua_pushvalue(L, i);
  593. }
  594. void call(int nresults)
  595. {
  596. lua_pcall(L, 2, nresults, 0);
  597. }
  598. #if CROWN_DEBUG
  599. Vector3* check_temporary(int i, const Vector3* p);
  600. Quaternion* check_temporary(int i, const Quaternion* p);
  601. Matrix4x4* check_temporary(int i, const Matrix4x4* p);
  602. void check_type(int i, const Gui* p)
  603. {
  604. if (CE_UNLIKELY(!is_pointer(i) || *(u32*)p != DEBUG_GUI_MARKER))
  605. {
  606. luaL_typerror(L, i, "Gui");
  607. CE_UNREACHABLE();
  608. }
  609. }
  610. void check_type(int i, const DebugLine* p)
  611. {
  612. if (CE_UNLIKELY(!is_pointer(i) || *(u32*)p != DEBUG_LINE_MARKER))
  613. {
  614. luaL_typerror(L, i, "DebugLine");
  615. CE_UNREACHABLE();
  616. }
  617. }
  618. void check_type(int i, const ResourcePackage* p)
  619. {
  620. if (CE_UNLIKELY(!is_pointer(i) || *(u32*)p != RESOURCE_PACKAGE_MARKER))
  621. {
  622. luaL_typerror(L, i, "ResourcePackage");
  623. CE_UNREACHABLE();
  624. }
  625. }
  626. void check_type(int i, const World* p)
  627. {
  628. if (CE_UNLIKELY(!is_pointer(i) || *(u32*)p != WORLD_MARKER))
  629. {
  630. luaL_typerror(L, i, "World");
  631. CE_UNREACHABLE();
  632. }
  633. }
  634. void check_type(int i, const SceneGraph* p)
  635. {
  636. if (CE_UNLIKELY(!is_pointer(i) || *(u32*)p != SCENE_GRAPH_MARKER))
  637. {
  638. luaL_typerror(L, i, "SceneGraph");
  639. CE_UNREACHABLE();
  640. }
  641. }
  642. void check_type(int i, const RenderWorld* p)
  643. {
  644. if (CE_UNLIKELY(!is_pointer(i) || *(u32*)p != RENDER_WORLD_MARKER))
  645. {
  646. luaL_typerror(L, i, "RenderWorld");
  647. CE_UNREACHABLE();
  648. }
  649. }
  650. void check_type(int i, const PhysicsWorld* p)
  651. {
  652. if (CE_UNLIKELY(!is_pointer(i) || *(u32*)p != PHYSICS_WORLD_MARKER))
  653. {
  654. luaL_typerror(L, i, "PhysicsWorld");
  655. CE_UNREACHABLE();
  656. }
  657. }
  658. void check_type(int i, const SoundWorld* p)
  659. {
  660. if (CE_UNLIKELY(!is_pointer(i) || *(u32*)p != SOUND_WORLD_MARKER))
  661. {
  662. luaL_typerror(L, i, "SoundWorld");
  663. CE_UNREACHABLE();
  664. }
  665. }
  666. void check_type(int i, const Level* p)
  667. {
  668. if (CE_UNLIKELY(!is_pointer(i) || *(u32*)p != LEVEL_MARKER))
  669. {
  670. luaL_typerror(L, i, "Level");
  671. CE_UNREACHABLE();
  672. }
  673. }
  674. void check_type(int i, const ScriptWorld* p)
  675. {
  676. if (CE_UNLIKELY(!is_pointer(i) || *(u32*)p != SCRIPT_WORLD_MARKER))
  677. {
  678. luaL_typerror(L, i, "ScriptWorld");
  679. CE_UNREACHABLE();
  680. }
  681. }
  682. void check_type(int i, const AnimationStateMachine* p)
  683. {
  684. if (CE_UNLIKELY(!is_pointer(i) || *(u32*)p != ANIMATION_STATE_MACHINE_MARKER))
  685. {
  686. luaL_typerror(L, i, "AnimationStateMachine");
  687. CE_UNREACHABLE();
  688. }
  689. }
  690. #endif // CROWN_DEBUG
  691. };
  692. } // namespace crown