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]
| 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 | * |
nothing calls this directly
no test coverage detected