Parcourir la source

sokol_debugtext.h: expose the internal string-format buffer to language bindings (used by sokol-zig)

Andre Weissflog il y a 3 semaines
Parent
commit
7457cae733
1 fichiers modifiés avec 13 ajouts et 0 suppressions
  1. 13 0
      util/sokol_debugtext.h

+ 13 - 0
util/sokol_debugtext.h

@@ -753,6 +753,9 @@ SOKOL_DEBUGTEXT_API_DECL void sdtx_putr(const char* str, int len);    // 'put ra
 SOKOL_DEBUGTEXT_API_DECL int sdtx_printf(const char* fmt, ...) SOKOL_DEBUGTEXT_PRINTF_ATTR;
 SOKOL_DEBUGTEXT_API_DECL int sdtx_printf(const char* fmt, ...) SOKOL_DEBUGTEXT_PRINTF_ATTR;
 SOKOL_DEBUGTEXT_API_DECL int sdtx_vprintf(const char* fmt, va_list args);
 SOKOL_DEBUGTEXT_API_DECL int sdtx_vprintf(const char* fmt, va_list args);
 
 
+/* language bindings helper: get the internal printf format buffer */
+SOKOL_DEBUGTEXT_API_DECL sdtx_range sdtx_get_cleared_fmt_buffer(void);
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 } /* extern "C" */
 } /* extern "C" */
 /* C++ const-ref wrappers */
 /* C++ const-ref wrappers */
@@ -4955,6 +4958,16 @@ SOKOL_DEBUGTEXT_API_DECL int sdtx_printf(const char* fmt, ...) {
     return res;
     return res;
 }
 }
 
 
+SOKOL_DEBUGTEXT_API_DECL sdtx_range sdtx_get_cleared_fmt_buffer(void) {
+    SOKOL_ASSERT(_SDTX_INIT_COOKIE == _sdtx.init_cookie);
+    SOKOL_ASSERT(_sdtx.fmt_buf && (_sdtx.fmt_buf_size >= 2));
+    memset(_sdtx.fmt_buf, 0, _sdtx.fmt_buf_size);
+    sdtx_range res; _sdtx_clear(&res, sizeof(res));
+    res.ptr = _sdtx.fmt_buf;
+    res.size = _sdtx.fmt_buf_size - 1;
+    return res;
+}
+
 SOKOL_API_IMPL void sdtx_draw(void) {
 SOKOL_API_IMPL void sdtx_draw(void) {
     SOKOL_ASSERT(_SDTX_INIT_COOKIE == _sdtx.init_cookie);
     SOKOL_ASSERT(_SDTX_INIT_COOKIE == _sdtx.init_cookie);
     _sdtx_context_t* ctx = _sdtx.cur_ctx;
     _sdtx_context_t* ctx = _sdtx.cur_ctx;