#include "Base.h" #include "ScriptController.h" #include "Light.h" #include "lua_Light.h" #include "lua_Global.h" namespace gameplay { void luaRegister_Light() { ScriptController* sc = ScriptController::getInstance(); const luaL_Reg lua_members[] = { {"addRef", lua_Light_addRef}, {"getColor", lua_Light_getColor}, {"getInnerAngle", lua_Light_getInnerAngle}, {"getInnerAngleCos", lua_Light_getInnerAngleCos}, {"getLightType", lua_Light_getLightType}, {"getNode", lua_Light_getNode}, {"getOuterAngle", lua_Light_getOuterAngle}, {"getOuterAngleCos", lua_Light_getOuterAngleCos}, {"getRange", lua_Light_getRange}, {"getRangeInverse", lua_Light_getRangeInverse}, {"getRefCount", lua_Light_getRefCount}, {"release", lua_Light_release}, {"setColor", lua_Light_setColor}, {"setInnerAngle", lua_Light_setInnerAngle}, {"setOuterAngle", lua_Light_setOuterAngle}, {"setRange", lua_Light_setRange}, {NULL, NULL} }; const luaL_Reg lua_statics[] = { {"createDirectional", lua_Light_static_createDirectional}, {"createPoint", lua_Light_static_createPoint}, {"createSpot", lua_Light_static_createSpot}, {NULL, NULL} }; std::vector scopePath; sc->registerClass("Light", lua_members, NULL, lua_Light__gc, lua_statics, scopePath); } static Light* getInstance(lua_State* state) { void* userdata = luaL_checkudata(state, 1, "Light"); luaL_argcheck(state, userdata != NULL, 1, "'Light' expected."); return (Light*)((ScriptController::LuaObject*)userdata)->instance; } int lua_Light__gc(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL)) { void* userdata = luaL_checkudata(state, 1, "Light"); luaL_argcheck(state, userdata != NULL, 1, "'Light' expected."); ScriptController::LuaObject* object = (ScriptController::LuaObject*)userdata; if (object->owns) { Light* instance = (Light*)object->instance; SAFE_RELEASE(instance); } return 0; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } int lua_Light_addRef(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL)) { Light* instance = getInstance(state); instance->addRef(); return 0; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } int lua_Light_getColor(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL)) { Light* instance = getInstance(state); void* returnPtr = (void*)&(instance->getColor()); if (returnPtr) { ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject)); object->instance = returnPtr; object->owns = false; luaL_getmetatable(state, "Vector3"); lua_setmetatable(state, -2); } else { lua_pushnil(state); } return 1; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } int lua_Light_getInnerAngle(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL)) { Light* instance = getInstance(state); float result = instance->getInnerAngle(); // Push the return value onto the stack. lua_pushnumber(state, result); return 1; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } int lua_Light_getInnerAngleCos(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL)) { Light* instance = getInstance(state); float result = instance->getInnerAngleCos(); // Push the return value onto the stack. lua_pushnumber(state, result); return 1; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } int lua_Light_getLightType(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL)) { Light* instance = getInstance(state); Light::Type result = instance->getLightType(); // Push the return value onto the stack. lua_pushstring(state, lua_stringFromEnum_LightType(result).c_str()); return 1; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } int lua_Light_getNode(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL)) { Light* instance = getInstance(state); void* returnPtr = (void*)instance->getNode(); if (returnPtr) { ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject)); object->instance = returnPtr; object->owns = false; luaL_getmetatable(state, "Node"); lua_setmetatable(state, -2); } else { lua_pushnil(state); } return 1; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } int lua_Light_getOuterAngle(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL)) { Light* instance = getInstance(state); float result = instance->getOuterAngle(); // Push the return value onto the stack. lua_pushnumber(state, result); return 1; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } int lua_Light_getOuterAngleCos(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL)) { Light* instance = getInstance(state); float result = instance->getOuterAngleCos(); // Push the return value onto the stack. lua_pushnumber(state, result); return 1; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } int lua_Light_getRange(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL)) { Light* instance = getInstance(state); float result = instance->getRange(); // Push the return value onto the stack. lua_pushnumber(state, result); return 1; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } int lua_Light_getRangeInverse(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL)) { Light* instance = getInstance(state); float result = instance->getRangeInverse(); // Push the return value onto the stack. lua_pushnumber(state, result); return 1; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } int lua_Light_getRefCount(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL)) { Light* instance = getInstance(state); unsigned int result = instance->getRefCount(); // Push the return value onto the stack. lua_pushunsigned(state, result); return 1; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } int lua_Light_release(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL)) { Light* instance = getInstance(state); instance->release(); return 0; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } int lua_Light_setColor(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 2: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) && (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL)) { // Get parameter 1 off the stack. Vector3* param1 = ScriptController::getInstance()->getObjectPointer(2, "Vector3", true); Light* instance = getInstance(state); instance->setColor(*param1); return 0; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 2)."); lua_error(state); break; } } return 0; } int lua_Light_setInnerAngle(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 2: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) && lua_type(state, 2) == LUA_TNUMBER) { // Get parameter 1 off the stack. float param1 = (float)luaL_checknumber(state, 2); Light* instance = getInstance(state); instance->setInnerAngle(param1); return 0; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 2)."); lua_error(state); break; } } return 0; } int lua_Light_setOuterAngle(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 2: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) && lua_type(state, 2) == LUA_TNUMBER) { // Get parameter 1 off the stack. float param1 = (float)luaL_checknumber(state, 2); Light* instance = getInstance(state); instance->setOuterAngle(param1); return 0; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 2)."); lua_error(state); break; } } return 0; } int lua_Light_setRange(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 2: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) && lua_type(state, 2) == LUA_TNUMBER) { // Get parameter 1 off the stack. float param1 = (float)luaL_checknumber(state, 2); Light* instance = getInstance(state); instance->setRange(param1); return 0; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 2)."); lua_error(state); break; } } return 0; } int lua_Light_static_createDirectional(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL)) { // Get parameter 1 off the stack. Vector3* param1 = ScriptController::getInstance()->getObjectPointer(1, "Vector3", true); void* returnPtr = (void*)Light::createDirectional(*param1); if (returnPtr) { ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject)); object->instance = returnPtr; object->owns = false; luaL_getmetatable(state, "Light"); lua_setmetatable(state, -2); } else { lua_pushnil(state); } return 1; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } int lua_Light_static_createPoint(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 2: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) && lua_type(state, 2) == LUA_TNUMBER) { // Get parameter 1 off the stack. Vector3* param1 = ScriptController::getInstance()->getObjectPointer(1, "Vector3", true); // Get parameter 2 off the stack. float param2 = (float)luaL_checknumber(state, 2); void* returnPtr = (void*)Light::createPoint(*param1, param2); if (returnPtr) { ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject)); object->instance = returnPtr; object->owns = false; luaL_getmetatable(state, "Light"); lua_setmetatable(state, -2); } else { lua_pushnil(state); } return 1; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 2)."); lua_error(state); break; } } return 0; } int lua_Light_static_createSpot(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 4: { if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) && lua_type(state, 2) == LUA_TNUMBER && lua_type(state, 3) == LUA_TNUMBER && lua_type(state, 4) == LUA_TNUMBER) { // Get parameter 1 off the stack. Vector3* param1 = ScriptController::getInstance()->getObjectPointer(1, "Vector3", true); // Get parameter 2 off the stack. float param2 = (float)luaL_checknumber(state, 2); // Get parameter 3 off the stack. float param3 = (float)luaL_checknumber(state, 3); // Get parameter 4 off the stack. float param4 = (float)luaL_checknumber(state, 4); void* returnPtr = (void*)Light::createSpot(*param1, param2, param3, param4); if (returnPtr) { ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject)); object->instance = returnPtr; object->owns = false; luaL_getmetatable(state, "Light"); lua_setmetatable(state, -2); } else { lua_pushnil(state); } return 1; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 4)."); lua_error(state); break; } } return 0; } }