Search code examples
lualuasocket

How To Require Lua Socket?


I'm very new to lua development with file manipulation, and now trying to import the lua socket package into my project according to this post, but I can't run even the code below.

I guess the error message indicates I need to import not only the socket.lua but also .\socket\core (probably .dll, since it doesn't have core.lua), while a reply at the post suggested importing only the file.

I'm stuck in just the beginning... What do I have to do for the next step?

local function main()
  local socket = require("socket")
end
main()

Exception in thread "main" com.naef.jnlua.LuaRuntimeException: ...n32.win32.x86_64\workspace\TestForCiv\src\socket.lua:13: module 'socket.core' not found:
    no field package.preload['socket.core']
    no file '.\socket\core.lua'
    no file 'C:\Program Files\Java\jre1.8.0_151\bin\lua\socket\core.lua'
    no file 'C:\Program Files\Java\jre1.8.0_151\bin\lua\socket\core\init.lua'
    ...(a bunch of no file errors continues)

Edit: I added the folder structure. Even I add the .dll file it returns the same error.

enter image description here


Solution

  • I don't know the details of you configuration, but try this

    require ("src.socket")
    

    you should require a module from the root path of the lib