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

Function ReadSerializedTable

engine/script/src/test/test_script_table.cpp:61–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59 */
60typedef double (*TableGenFunc)(double);
61static int ReadSerializedTable(lua_State* L, uint8_t* source, uint32_t source_length, TableGenFunc fn, int key_stride)
62{
63 int error = 0;
64 const double epsilon = 1.0e-7f;
65 char* aligned_buf = (char*)source;
66
67 dmScript::PushTable(L, aligned_buf, source_length);
68
69 for (uint32_t i=0; i<0xfff; ++i)
70 {
71 lua_pushnumber(L, i * key_stride);
72 lua_gettable(L, -2);
73 EXPECT_EQ(LUA_TNUMBER, lua_type(L, -1));
74 if (LUA_TNUMBER != lua_type(L, -1))
75 {
76 printf("Invalid key on row %d\n", i);
77 }
78 double value_read = lua_tonumber(L, -1);
79 double value_expected = fn(2.0 * M_PI * (double)i / (double)0xffff);
80 double diff = fabs(value_read - value_expected);
81 EXPECT_GT(epsilon, diff);
82 lua_pop(L, 1);
83
84 if (epsilon < diff)
85 {
86 error = 1;
87 break;
88 }
89 }
90
91 lua_pop(L, 1);
92
93 return error;
94}
95
96static int ReadUnsupportedVersion(lua_State* L)
97{

Callers 4

ReadCosTableDataOriginalFunction · 0.85
ReadSinTableDataOriginalFunction · 0.85

Calls 7

PushTableFunction · 0.85
lua_pushnumberFunction · 0.85
lua_gettableFunction · 0.85
lua_typeFunction · 0.85
lua_tonumberFunction · 0.85
fnFunction · 0.85
fabsFunction · 0.85

Tested by

no test coverage detected