Strange behavior of if_lua (String comparison) #333

Closed
thinca opened this Issue Aug 21, 2016 · 6 comments

Comments

Projects
None yet
3 participants

thinca commented Aug 21, 2016

The behavior of multibyte string comparison is strange in if_lua of MacVim.

Assumption

  • encoding=utf-8
  • = 0xE38182 (UTF-8)
  • = 0xE38184 (UTF-8)

Examples

In Lua:

% lua
Lua 5.2.4  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> print('あ' < 'い')
true
> print('ああ' < 'い')
true
>

OK. Expected behavior.

In Vim (Linux):

:lua print('あ' < 'い')
true
:lua print('ああ' < 'い')
true

OK. Expected behavior.

In MacVim:

:lua print('あ' < 'い')
true
:lua print('ああ' < 'い')
false

Last one is strange. It should be true.

Environment

OS X El Capitan 10.11.6
MacVim 7.4.2228 (Installed by brew install --HEAD macvim-dev/macvim/macvim --with-lua)

Owner

splhack commented Sep 14, 2016

Could you check it with snapshot-110 binary?
https://github.com/macvim-dev/macvim/releases/tag/snapshot-110

btw https://github.com/macvim-dev/homebrew-macvim doesn't have --with-lua option.

thinca commented Sep 16, 2016

Could you check it with snapshot-110 binary?

I tried it, and the problem reproduced.

btw https://github.com/macvim-dev/homebrew-macvim doesn't have --with-lua option.

Oh, I didn't know. Thanks!

Owner

splhack commented Sep 16, 2016

hmm, I can't repro it.

$ brew uninstall --force lua
$ brew install lua         
==> Downloading https://homebrew.bintray.com/bottles/lua-5.2.4_4.el_capitan.bott
==> Pouring lua-5.2.4_4.el_capitan.bottle.tar.gz
==> Caveats
Please be aware due to the way Luarocks is designed any binaries installed
via Luarocks-5.2 AND 5.1 will overwrite each other in /usr/local/bin.

This is, for now, unavoidable. If this is troublesome for you, you can build
rocks with the `--tree=` command to a special, non-conflicting location and
then add that to your `$PATH`.
==> Summary
🍺  /usr/local/Cellar/lua/5.2.4_4: 143 files, 697.4K

$ rm -rf ~/.vim* ~/.gvimrc 
$ killall -9 MacVim
$ killall -9 Vim
$ open snapshot-110/MacVim.app

In MacVim snapshot-110

:version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Sep 14 2016 03:42:03)
MacOS X (unix) version
Included patches: 1-3
Compiled by travis@Traviss-Mac-659.local
...

:scriptnames
  1: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/vimrc
  2: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/defaults.vim
  3: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/syntax/syntax.vim
  4: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/syntax/synload.vim
  5: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/syntax/syncolor.vim
  6: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/filetype.vim
  7: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/menu.vim
  8: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/autoload/paste.vim
  9: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/ftplugin.vim
 10: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/indent.vim
 11: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/plugin/getscriptPlugin.vim
 12: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/plugin/gzip.vim
 13: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/plugin/logiPat.vim
 14: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/plugin/manpager.vim
 15: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/plugin/matchparen.vim
 16: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/plugin/netrwPlugin.vim
 17: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/plugin/rrhelper.vim
 18: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/plugin/spellfile.vim
 19: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/plugin/tarPlugin.vim
 20: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/plugin/tohtml.vim
 21: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/plugin/vimballPlugin.vim
 22: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/plugin/zipPlugin.vim
 23: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/gvimrc
 24: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/colors/macvim.vim
 25: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/syntax/vim.vim
 26: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/syntax/lua.vim
 27: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/syntax/perl.vim
 28: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/syntax/pod.vim
 29: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/syntax/ruby.vim
 30: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/syntax/python.vim
 31: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/ftplugin/vim.vim
 32: /Volumes/MacVim/MacVim.app/Contents/Resources/vim/runtime/indent/vim.vim
Press ENTER or type command to continue

:set luadll?
    luadll=liblua.5.2.dylib 

:lua print('ああ' < 'い')
true
Contributor

ichizok commented Sep 20, 2016

This issue is concerned with OS locale.

example:

% lua
Lua 5.2.4  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> print('あ' < 'い')
true
> print('ああ' < 'い')
true
> print(os.setlocale(nil))
C/ja_JP.UTF-8/C/C/C/C
> print(os.setlocale(''))
ja_JP.UTF-8
> print('ああ' < 'い')
false

Lua comparing-strings uses strcoll, which is based on current locale (refering to LC_COLLATE).
(We can set current locale by setlocale, or environment variables LC_ALL and other LC_*)
On OS X, the order of multibyte strings based on locale is different from Linux Glibc;

Linux: 'あ' < 'ああ' < 'い’ (dictionary order)
OS X: 'あ' < 'い' < ... < 'ん' < 'ああ'

Thus, when locale is set to other than "C" or "POSIX", the result of comparing multibyte strings may be environment specific.

Owner

splhack commented Sep 20, 2016

@ichizok 👍

splhack closed this Sep 20, 2016

thinca commented Sep 23, 2016

@ichizok Thank you!

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