starwing / luautf8

a utf-8 support module for Lua and LuaJIT.
MIT License
412 stars 68 forks source link

undefined symbol: lua_tointeger #10

Closed tastyminerals closed 6 years ago

tastyminerals commented 8 years ago

Default interpreter lua5.3, Using snippet:

  local file = assert(io.open(fname, 'r'))
  local fdata = file:read("*all")
  print(utf8.lower(fdata))

produces the following error:

[tastyminerals@dell-tasty sandbox]$ lua test.lua news
lua: error loading module 'lua-utf8' from file '/usr/lib/lua/5.3/lua-utf8.so':
    /usr/lib/lua/5.3/lua-utf8.so: undefined symbol: lua_tointeger
stack traceback:
    [C]: in ?
    [C]: in function 'require'
    test.lua:3: in main chunk
    [C]: in ?
tastyminerals commented 8 years ago

oh, that was due to local utf8 = require 'lua-utf8'. When I switch to utf8 = require 'lua-utf8', everything works.

starwing commented 8 years ago

lua_tointeger() is a symbol in Lua5.3, but not before.

if you use Lua 5.3, and compile lua-utf8 for it, the lua-utf8.so will require lua executable export this symbol. if you compile lua-utf8 for other Lua version, it's not needed.

tastyminerals commented 8 years ago

Sorry, what does "symbol in Lua 5.3" mean?

starwing commented 8 years ago

Lua is a library that export it's interface to outside world. When in Windows, lua53.dll exports it's lua* functions as DLL export symbol. and in Linux. we usually static build Lua into one executable. This executable (usually named "lua") export lua* functions as the global symbol of executable file (which is support by ELF file format in Linux). So In Linux, a C module loaded in Lua will look into global namespace to find lua_* functions to use. lua_tointeger() is a macro in Lua 5.1 and Lua 5.2, but in Lua 5.3 it became a real function, means if you compile any module against Lua 5.3, the module will find lua_tointeger() symbol in global namespace, If it can find, the load will failure.