Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions spec/lua/stack/chunk_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ module Lua::StackMixin
)).should be_a Function
s.close
end

context "with multibyte UTF-8 characters" do
it "keeps the full chunk when a comment contains multibyte characters" do
s = Stack.new
s.run(%q(
-- é à ç — สวัสดี 你好
return 42
)).should eq 42
s.close
end

it "passes multibyte bytes through inside string literals" do
s = Stack.new
s.run(%q( return "é — สวัสดี 你好" )).should eq "é — สวัสดี 你好"
s.close
end
end
end

describe "#run" do
Expand Down
2 changes: 1 addition & 1 deletion src/lua/stack/chunk.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Lua
# } # => 8
# ```
def run(buff : String, name : String? = nil)
call = CALL.new LibLua.l_loadbufferx @state, buff, buff.size, name || buff.strip, nil
call = CALL.new LibLua.l_loadbufferx @state, buff, buff.bytesize, name || buff.strip, nil
raise error(call, pop) if call != CALL::OK
call_and_return size
end
Expand Down
2 changes: 1 addition & 1 deletion src/lua/stack/util.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module Lua
end

protected def pick_results(start, finish = size)
elements = (start..finish).map { pop }
elements = (start..finish).map { pop.as(::Lua::Type) }
elements.size > 1 ? elements : elements.first?
end
end
Expand Down
Loading