Lua c api: how to press a string with a null character in the middle?

usually i would just use

lua_pushstring(lua_State* L, const char* s); 

however, the line I want to click may have a null character. How to do it?

+4
source share
1 answer

Use lua_pushlstring .

 void lua_pushlstring (lua_State *L, const char *s, size_t len); 

Pushes the line pointed to by s, with the size len on the stack. Lua makes (or reuses) an internal copy of the given string, so the memory in s can be freed or reused right after the function returns. A string may contain embedded zeros.

+11
source

Source: https://habr.com/ru/post/1309277/


All Articles