MCPcopy Create free account
hub / github.com/defold/defold / Vector_new

Function Vector_new

engine/script/src/script_vmath.cpp:899–923  ·  view source on GitHub ↗

create a new vector from a table of values * Creates a vector of arbitrary size. The vector is initialized * with numeric values from a table. * * [icon:attention] The table values are converted to floating point * values. If a value cannot be converted, a 0 is stored in that * value position in the vector. * * @name vmath.vector * @param t [type:table]

Source from the content-addressed store, hash-verified

897 * ```
898 */
899 static int Vector_new(lua_State* L)
900 {
901 FloatVector *v;
902 if (lua_gettop(L) == 0)
903 {
904 v = new FloatVector(0);
905 }
906 else
907 {
908 luaL_checktype(L, 1, LUA_TTABLE);
909 int array_size = lua_objlen(L, 1);
910 v = new FloatVector(array_size);
911
912 for (int i = 0; i < array_size; i++)
913 {
914 lua_pushnumber(L, i+1);
915 lua_gettable(L, 1);
916 v->values[i] = (float) lua_tonumber(L, -1);
917 lua_pop(L, 1);
918 }
919 }
920
921 PushVector(L, v);
922 return 1;
923 }
924
925 /*# creates a new zero vector
926 *

Callers

nothing calls this directly

Calls 7

lua_gettopFunction · 0.85
luaL_checktypeFunction · 0.85
lua_objlenFunction · 0.85
lua_pushnumberFunction · 0.85
lua_gettableFunction · 0.85
lua_tonumberFunction · 0.85
PushVectorFunction · 0.85

Tested by

no test coverage detected