| 43 | sol::state _luaState; |
| 44 | |
| 45 | void setupLuaState(sol::state* p_State) |
| 46 | { |
| 47 | _luaState = sol::state(); |
| 48 | |
| 49 | p_State->open_libraries(sol::lib::base, sol::lib::math, sol::lib::table); |
| 50 | |
| 51 | p_State->create_named_table("methods", "tick", p_State->create_table(), |
| 52 | "onCreate", p_State->create_table(), "onDestroy", |
| 53 | p_State->create_table()); |
| 54 | |
| 55 | p_State->script("function registerTickFunction(id, func)\n" |
| 56 | "methods[\"tick\"][id] = func\n" |
| 57 | "end\n"); |
| 58 | p_State->script("function registerOnCreateFunction(id, func)\n" |
| 59 | "methods[\"onCreate\"][id] = func\n" |
| 60 | "end\n"); |
| 61 | p_State->script("function registerOnDestroyFunction(id, func)\n" |
| 62 | "methods[\"onDestroy\"][id] = func\n" |
| 63 | "end\n"); |
| 64 | |
| 65 | sol::table glmTable = p_State->create_named_table("glm"); |
| 66 | |
| 67 | sol::table nodeComponentTable = p_State->create_named_table("nodeComponent"); |
| 68 | sol::table meshComponentTable = p_State->create_named_table("meshComponent"); |
| 69 | |
| 70 | sol::table worldTable = p_State->create_named_table("world"); |
| 71 | |
| 72 | sol::table entityTable = p_State->create_named_table("entity"); |
| 73 | sol::table inputSystemTable = p_State->create_named_table("inputSystem"); |
| 74 | |
| 75 | { |
| 76 | inputSystemTable["keyState"] = &Input::System::getKeyState; |
| 77 | inputSystemTable["lastMousePos"] = &Input::System::getLastMousePos; |
| 78 | inputSystemTable["lastMousePosViewport"] = |
| 79 | &Input::System::getLastMousePosViewport; |
| 80 | inputSystemTable["lastMousePosRel"] = &Input::System::getLastMousePosRel; |
| 81 | } |
| 82 | |
| 83 | { |
| 84 | p_State->new_usertype<glm::vec2, float, float>("Vec2", "x", &glm::vec2::x, |
| 85 | "y", &glm::vec2::y); |
| 86 | p_State->new_usertype<glm::vec3, float, float, float>( |
| 87 | "Vec3", "x", &glm::vec3::x, "y", &glm::vec3::y, "z", &glm::vec3::z); |
| 88 | p_State->new_usertype<glm::vec4, float, float, float, float>( |
| 89 | "Vec4", "x", &glm::vec4::x, "y", &glm::vec4::y, "z", &glm::vec4::z, "w", |
| 90 | &glm::vec4::w); |
| 91 | |
| 92 | sol::constructors<sol::types<float, float, float, float>, |
| 93 | sol::types<const glm::vec3&>> |
| 94 | quatConstructors; |
| 95 | sol::usertype<glm::quat> quatUserType(quatConstructors, "x", &glm::quat::x, |
| 96 | "y", &glm::quat::y, "z", |
| 97 | &glm::quat::z, "w", &glm::quat::w); |
| 98 | |
| 99 | p_State->set_usertype("Quat", quatUserType); |
| 100 | |
| 101 | glmTable["rotate"] = |
| 102 | (glm::vec3(*)(const glm::quat&, const glm::vec3&)) & glm::rotate; |