소스 검색

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

Andre Weissflog 1 주 전
부모
커밋
7457cae733
1개의 변경된 파일13개의 추가작업 그리고 0개의 파일을 삭제
  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_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
 } /* extern "C" */
 /* C++ const-ref wrappers */
@@ -4955,6 +4958,16 @@ SOKOL_DEBUGTEXT_API_DECL int sdtx_printf(const char* fmt, ...) {
     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_ASSERT(_SDTX_INIT_COOKIE == _sdtx.init_cookie);
     _sdtx_context_t* ctx = _sdtx.cur_ctx;