delete one or more game object instances * Delete one or more game objects identified by id. Deletion is asynchronous meaning that * the game object(s) are scheduled for deletion which will happen at the end of the current * frame. Note that game objects scheduled for deletion will be counted against * `max_instances` in "game.project" until they are actually removed. *
| 1910 | * |
| 1911 | */ |
| 1912 | static int Script_Delete(lua_State* L) |
| 1913 | { |
| 1914 | int args = lua_gettop(L); |
| 1915 | |
| 1916 | if(args > 2) |
| 1917 | { |
| 1918 | return luaL_error(L, "go.delete invoked with too many argumengs"); |
| 1919 | } |
| 1920 | |
| 1921 | // deduct recursive bool parameter (optional last parameter) |
| 1922 | bool recursive = false; |
| 1923 | if(args != 0) |
| 1924 | { |
| 1925 | if(lua_isboolean(L, 1)) |
| 1926 | { |
| 1927 | // if argument #1 is boolean, no more arguments are accepted |
| 1928 | if(args > 1) |
| 1929 | { |
| 1930 | return luaL_error(L, "go.delete expected one argument when argument #1 is boolean type"); |
| 1931 | } |
| 1932 | recursive = lua_toboolean(L, 1); |
| 1933 | lua_pop(L, 1); |
| 1934 | --args; |
| 1935 | } |
| 1936 | else if(args > 1) |
| 1937 | { |
| 1938 | // if argument #1 isn't a boolean, it's resolved later. Argument #2 is required to be a boolean |
| 1939 | if(lua_isboolean(L, 2)) |
| 1940 | { |
| 1941 | recursive = lua_toboolean(L, 2); |
| 1942 | } |
| 1943 | else |
| 1944 | { |
| 1945 | return luaL_error(L, "go.delete expected boolean as argument #2"); |
| 1946 | } |
| 1947 | lua_pop(L, 1); |
| 1948 | --args; |
| 1949 | } |
| 1950 | } |
| 1951 | |
| 1952 | // handle optional parameter #1 is table or nil |
| 1953 | if(args != 0) |
| 1954 | { |
| 1955 | if(lua_istable(L, 1)) |
| 1956 | { |
| 1957 | int result = DeleteGOTable(L, recursive); |
| 1958 | if(result == 0) |
| 1959 | { |
| 1960 | assert(args == lua_gettop(L)); |
| 1961 | } |
| 1962 | return result; |
| 1963 | } |
| 1964 | else if(lua_isnil(L, 1)) |
| 1965 | { |
| 1966 | return luaL_error(L, "go.delete() invoked with first argument 'id' set to 'nil'"); |
| 1967 | } |
| 1968 | } |
| 1969 |
nothing calls this directly
no test coverage detected