Skip to content

Instantly share code, notes, and snippets.

@outsinre
Created October 17, 2023 14:46
Show Gist options
  • Save outsinre/d9f04f9a92e2f0f013ccdc5cf4d44c64 to your computer and use it in GitHub Desktop.
Save outsinre/d9f04f9a92e2f0f013ccdc5cf4d44c64 to your computer and use it in GitHub Desktop.
string buffer consumption
local sb = require "string.buffer"
local buff = sb.new()
buff:put("a", "", "c")
print("buff len after put: ", #buff)
local str = buff:get()
print("1st get: ", str)
print("buff len after 1st get: ", #buff)
str = buff:get()
print("2nd get: ", str)
@outsinre
Copy link
Author

~ $ luajit test.lua

The 1st buffer:get() will consume and empty the buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment