Skip to content

Commit 8f8c940

Browse files
authored
Fixed parsing variadic length C array through script eval (#12)
Previously it was working due to fallback to string conversion.
1 parent 8f68f59 commit 8f8c940

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/imvue_element.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,23 @@ namespace ImVue {
351351
return true;
352352
}
353353

354+
template<class C>
355+
typename std::enable_if<std::is_arithmetic<C>::value, bool>::type
356+
read(Object& value, C** dest)
357+
{
358+
if(*dest) {
359+
ImGui::MemFree(*dest);
360+
*dest = NULL;
361+
}
362+
ImVector<C> values;
363+
for(Object::iterator iter = value.begin(); iter != value.end(); ++iter) {
364+
values.push_back(iter.value.as<C>());
365+
}
366+
*dest = (C*)ImGui::MemAlloc(values.size_in_bytes());
367+
memcpy(*dest, values.Data, values.size_in_bytes());
368+
return true;
369+
}
370+
354371
template<class C>
355372
typename std::enable_if<std::is_arithmetic<C>::value, bool>::type
356373
read(Object& value, C* dest)

tests/unit/parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ const char* dataBind = "<template>"
252252
":i16='-32765' :i32='-65536' :i64='-1073741823' "
253253
":vec2='{2,2}' :vec4='{2,2,2,2}' "
254254
":ch='\"hello\"' "
255-
":arr-fixed='{1,2,3}' arr-variadic='{1,2,3,4,5}' "
255+
":arr-fixed='{1,2,3}' :arr-variadic='{1,2,3,4,5}' "
256256
":float='0.1' :double='0.05' "
257257
":object='{it=\"works\"}'"
258258
"/>"

0 commit comments

Comments
 (0)