forked from cory/tildefriends
core: Add a helper for getting a property by string as a string. I've typed this too much.
This commit is contained in:
@@ -502,6 +502,24 @@ int tf_util_get_length(JSContext* context, JSValue value)
|
||||
return result;
|
||||
}
|
||||
|
||||
const char* tf_util_get_property_as_string(JSContext* context, JSValue object, const char* key)
|
||||
{
|
||||
if (!JS_IsObject(object))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JSValue value = JS_GetPropertyStr(context, object, key);
|
||||
if (JS_IsUndefined(value))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* string = JS_ToCString(context, value);
|
||||
JS_FreeValue(context, value);
|
||||
return string;
|
||||
}
|
||||
|
||||
int tf_util_insert_index(const void* key, const void* base, size_t count, size_t size, int (*compare)(const void*, const void*))
|
||||
{
|
||||
int lower = 0;
|
||||
|
||||
Reference in New Issue
Block a user