diff --git a/spec/lua/stack/chunk_spec.cr b/spec/lua/stack/chunk_spec.cr index 763f119..0495f67 100644 --- a/spec/lua/stack/chunk_spec.cr +++ b/spec/lua/stack/chunk_spec.cr @@ -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 diff --git a/src/lua/stack/chunk.cr b/src/lua/stack/chunk.cr index 948256c..d575a43 100644 --- a/src/lua/stack/chunk.cr +++ b/src/lua/stack/chunk.cr @@ -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 diff --git a/src/lua/stack/util.cr b/src/lua/stack/util.cr index df7aa58..a8f626a 100644 --- a/src/lua/stack/util.cr +++ b/src/lua/stack/util.cr @@ -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