Browse Source

deps/obs-scripting: Fix script_log in python to append newline

jp9000 7 years ago
parent
commit
3259269c99
1 changed files with 17 additions and 3 deletions
  1. 17 3
      deps/obs-scripting/obs-scripting-python.c

+ 17 - 3
deps/obs-scripting/obs-scripting-python.c

@@ -35,12 +35,12 @@ import os\n\
 import obspython\n\
 import obspython\n\
 class stdout_logger(object):\n\
 class stdout_logger(object):\n\
 	def write(self, message):\n\
 	def write(self, message):\n\
-		obspython.script_log(obspython.LOG_INFO, message)\n\
+		obspython.script_log_no_endl(obspython.LOG_INFO, message)\n\
 	def flush(self):\n\
 	def flush(self):\n\
 		pass\n\
 		pass\n\
 class stderr_logger(object):\n\
 class stderr_logger(object):\n\
 	def write(self, message):\n\
 	def write(self, message):\n\
-		obspython.script_log(obspython.LOG_ERROR, message)\n\
+		obspython.script_log_no_endl(obspython.LOG_ERROR, message)\n\
 	def flush(self):\n\
 	def flush(self):\n\
 		pass\n\
 		pass\n\
 os.environ['PYTHONUNBUFFERED'] = '1'\n\
 os.environ['PYTHONUNBUFFERED'] = '1'\n\
@@ -1164,7 +1164,8 @@ static PyObject *sceneitem_list_release(PyObject *self, PyObject *args)
 
 
 struct dstr cur_py_log_chunk = {0};
 struct dstr cur_py_log_chunk = {0};
 
 
-static PyObject *py_script_log(PyObject *self, PyObject *args)
+static PyObject *py_script_log_internal(PyObject *self, PyObject *args,
+		bool add_endl)
 {
 {
 	static bool calling_self = false;
 	static bool calling_self = false;
 	int log_level;
 	int log_level;
@@ -1184,6 +1185,8 @@ static PyObject *py_script_log(PyObject *self, PyObject *args)
 		goto fail;
 		goto fail;
 
 
 	dstr_cat(&cur_py_log_chunk, msg);
 	dstr_cat(&cur_py_log_chunk, msg);
+	if (add_endl)
+		dstr_cat(&cur_py_log_chunk, "\n");
 
 
 	const char *start = cur_py_log_chunk.array;
 	const char *start = cur_py_log_chunk.array;
 	char *endl = strchr(start, '\n');
 	char *endl = strchr(start, '\n');
@@ -1210,6 +1213,16 @@ fail:
 	return python_none();
 	return python_none();
 }
 }
 
 
+static PyObject *py_script_log_no_endl(PyObject *self, PyObject *args)
+{
+	return py_script_log_internal(self, args, false);
+}
+
+static PyObject *py_script_log(PyObject *self, PyObject *args)
+{
+	return py_script_log_internal(self, args, true);
+}
+
 /* -------------------------------------------- */
 /* -------------------------------------------- */
 
 
 static void add_hook_functions(PyObject *module)
 static void add_hook_functions(PyObject *module)
@@ -1217,6 +1230,7 @@ static void add_hook_functions(PyObject *module)
 	static PyMethodDef funcs[] = {
 	static PyMethodDef funcs[] = {
 #define DEF_FUNC(n, c) {n, c, METH_VARARGS, NULL}
 #define DEF_FUNC(n, c) {n, c, METH_VARARGS, NULL}
 
 
+		DEF_FUNC("script_log_no_endl", py_script_log_no_endl),
 		DEF_FUNC("script_log", py_script_log),
 		DEF_FUNC("script_log", py_script_log),
 		DEF_FUNC("timer_remove", timer_remove),
 		DEF_FUNC("timer_remove", timer_remove),
 		DEF_FUNC("timer_add", timer_add),
 		DEF_FUNC("timer_add", timer_add),