Просмотр исходного кода

libobs: Add obs_data_get_last_json()

Helper function to return the last generated json string for this
object.
jp9000 4 лет назад
Родитель
Сommit
74c2379eba
3 измененных файлов с 19 добавлено и 0 удалено
  1. 13 0
      docs/sphinx/reference-settings.rst
  2. 5 0
      libobs/obs-data.c
  3. 1 0
      libobs/obs-data.h

+ 13 - 0
docs/sphinx/reference-settings.rst

@@ -67,6 +67,19 @@ General Functions
 
 .. function:: const char *obs_data_get_json(obs_data_t *data)
 
+   Generates a new json string. The string allocation is stored within
+   the data object itself, and does not need to be manually freed.
+
+   :return: Json string for this object
+
+---------------------
+
+.. function:: const char *obs_data_get_last_json(obs_data_t *data)
+
+   Returns the last json string generated for this data object. Does not
+   generate a new string. Use :c:func:`obs_data_get_json()` to generate
+   a json string first.
+
    :return: Json string for this object
 
 ---------------------

+ 5 - 0
libobs/obs-data.c

@@ -742,6 +742,11 @@ const char *obs_data_get_json(obs_data_t *data)
 	return data->json;
 }
 
+const char *obs_data_get_last_json(obs_data_t *data)
+{
+	return data ? data->json : NULL;
+}
+
 bool obs_data_save_json(obs_data_t *data, const char *file)
 {
 	const char *json = obs_data_get_json(data);

+ 1 - 0
libobs/obs-data.h

@@ -70,6 +70,7 @@ EXPORT void obs_data_addref(obs_data_t *data);
 EXPORT void obs_data_release(obs_data_t *data);
 
 EXPORT const char *obs_data_get_json(obs_data_t *data);
+EXPORT const char *obs_data_get_last_json(obs_data_t *data);
 EXPORT bool obs_data_save_json(obs_data_t *data, const char *file);
 EXPORT bool obs_data_save_json_safe(obs_data_t *data, const char *file,
 				    const char *temp_ext,