2
0

lua_environment.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #pragma once
  6. #include "config.h"
  7. #include "types.h"
  8. #include "macros.h"
  9. #include "resource_types.h"
  10. #include "math_types.h" // HACK
  11. #include "lua.hpp"
  12. namespace crown
  13. {
  14. enum LuaArgumentType
  15. {
  16. ARGUMENT_FLOAT
  17. };
  18. // HACK
  19. struct Actor;
  20. struct Unit;
  21. /// LuaEnvironment is a wrapper of a subset of Lua functions and
  22. /// provides utilities for extending Lua
  23. struct LuaEnvironment
  24. {
  25. LuaEnvironment();
  26. ~LuaEnvironment();
  27. void load_libs();
  28. void execute(const LuaResource* lr);
  29. /// Loads and executes the given @a s lua string.
  30. void execute_string(const char* s);
  31. /// Loads the function with the given @a name and @a func into the table @a module.
  32. void load_module_function(const char* module, const char* name, const lua_CFunction func);
  33. void load_module_function(const char* module, const char* name, const char* value);
  34. void load_module_constructor(const char* module, const lua_CFunction func);
  35. /// Loads the enum with the given @a name and @a value into the table @a module.
  36. void load_module_enum(const char* module, const char* name, uint32_t value);
  37. /// Calls the global function @a func with @a argc argument number.
  38. /// Each argument is a pair (type, value).
  39. /// Example call:
  40. /// call_global("myfunc", 1, ARGUMENT_FLOAT, 3.14f)
  41. /// Returns true if success, false otherwise
  42. void call_global(const char* func, uint8_t argc, ...);
  43. void clear_temporaries();
  44. Vector3* next_vector3(const Vector3& v);
  45. Quaternion* next_quaternion(const Quaternion& q);
  46. Matrix4x4* next_matrix4x4(const Matrix4x4& m);
  47. bool is_vector3(int i);
  48. bool is_quaternion(int i);
  49. bool is_matrix4x4(int i);
  50. // FIXME
  51. void call_physics_callback(Actor* actor_0, Actor* actor_1, Unit* unit_0, Unit* unit_1, const Vector3& where, const Vector3& normal, const char* type);
  52. void call_trigger_callback(Actor* trigger, Actor* other, const char* type);
  53. private:
  54. lua_State* L;
  55. uint32_t _vec3_used;
  56. Vector3 _vec3_buffer[CROWN_MAX_LUA_VECTOR3];
  57. uint32_t _quat_used;
  58. Quaternion _quat_buffer[CROWN_MAX_LUA_QUATERNION];
  59. uint32_t _mat4_used;
  60. Matrix4x4 s_mat4_buffer[CROWN_MAX_LUA_MATRIX4X4];
  61. private:
  62. // Disable copying
  63. LuaEnvironment(const LuaEnvironment&);
  64. LuaEnvironment& operator=(const LuaEnvironment&);
  65. };
  66. } // namespace crown