define a property for the script * This function defines a property which can then be used in the script through the self-reference. * The properties defined this way are automatically exposed in the editor in game objects and collections which use the script. * Note that you can only use this function outside any callback-functions like init and update. * * @name go.prope
| 2009 | * ``` |
| 2010 | */ |
| 2011 | int Script_Property(lua_State* L) |
| 2012 | { |
| 2013 | int top = lua_gettop(L); |
| 2014 | (void)top; |
| 2015 | |
| 2016 | Script* script = GetScript(L); |
| 2017 | |
| 2018 | if (script == 0x0) |
| 2019 | { |
| 2020 | return luaL_error(L, "go.property can only be called outside the functions."); |
| 2021 | } |
| 2022 | |
| 2023 | const char* id = luaL_checkstring(L, 1); |
| 2024 | (void)id; |
| 2025 | |
| 2026 | bool valid_type = false; |
| 2027 | if (lua_isnumber(L, 2)) |
| 2028 | { |
| 2029 | valid_type = true; |
| 2030 | } |
| 2031 | else if (dmScript::IsURL(L, 2)) |
| 2032 | { |
| 2033 | valid_type = true; |
| 2034 | } |
| 2035 | else if (dmScript::IsHash(L, 2)) |
| 2036 | { |
| 2037 | valid_type = true; |
| 2038 | } |
| 2039 | else if (dmScript::ToVector3(L, 2) != 0) |
| 2040 | { |
| 2041 | valid_type = true; |
| 2042 | } |
| 2043 | else if (dmScript::ToVector4(L, 2) != 0) |
| 2044 | { |
| 2045 | valid_type = true; |
| 2046 | } |
| 2047 | else if (dmScript::ToQuat(L, 2) != 0) |
| 2048 | { |
| 2049 | valid_type = true; |
| 2050 | } |
| 2051 | else if (lua_isboolean(L, 2)) |
| 2052 | { |
| 2053 | valid_type = true; |
| 2054 | } |
| 2055 | if (!valid_type) |
| 2056 | { |
| 2057 | return luaL_error(L, "Invalid type (%s) supplied to go.property, must be either a number, boolean, hash, URL, vector3, vector4 or quaternion.", lua_typename(L, lua_type(L, 2))); |
| 2058 | } |
| 2059 | assert(top == lua_gettop(L)); |
| 2060 | return 0; |
| 2061 | } |
| 2062 | |
| 2063 | |
| 2064 | /*# check if the specified game object exists |
nothing calls this directly
no test coverage detected