1

I have a simple test.lua script that creates a window using iuplua. I call it with lua C:\path\to\test.lua. If I call it from C:\lua-5.4.4\iuplua where all the iup libraries at, everything is fine no matter where the script itself is placed. The line from command prompt looks like that:

C:\lua-5.4.4\iuplua>lua C:\Users\username\Desktop\test.lua

But if I call it from any other directory but iuplua I get such error:

C:\Users\username\Desktop>lua test.lua
lua: error loading module 'iuplua' from file 'C:\lua-5.4.4\iuplua\Lua54\iuplua54.dll':
        The specified module could not be found.

LUA_PATH:

C:\lua-5.4.4\bin\lua\?.lua
C:\lua-5.4.4\bin\lua\?\init.lua
C:\lua-5.4.4\bin\?.lua
C:\lua-5.4.4\bin\?\init.lua
C:\lua-5.4.4\bin\..\share\lua\5.4\?.lua
C:\lua-5.4.4\bin\..\share\lua\5.4\?\init.lua
.\?.lua
.\?\init.lua

LUA_CPATH:

C:\lua-5.4.4\bin\?.dll
C:\lua-5.4.4\bin\..\lib\lua\5.4\?.dll
C:\lua-5.4.4\bin\loadall.dll
.\?.dll
C:\lua-5.4.4\iuplua\Lua54\?54.dll
C:\lua-5.4.4\iuplua\Lua54\?.dll
C:\lua-5.4.4\iuplua\?54.dll
C:\lua-5.4.4\iuplua\?.dll

Last 4 lines in LUA_CPATH are added by me, but if I put package.cpath = package.cpath..";these 4 lines" at the beginning of the script the result is the same.

OS is Windows 10, Lua version is 5.4.4, IUP version is 3.30, I didn't build it but downloaded binaries and Lua bindings from SourceForge: iup-3.30_Win64_dll16_lib and iup-3.30-Lua54_Win64_dll16_lib.

Can I do something to be able to launch lua not from iuplua folder but from everywhere I want?

Sun of A beach
  • 171
  • 1
  • 10
  • Your `package.path` looks non-standard. – ESkri Mar 01 '23 at 13:09
  • @ESkri I'm not sure about it... May be it was modified by luarocks somehow during installation... I tried to remove LUA_PATH from system variables entirely, it didn't change anything. And if I remove LUA_CPATH, then my code stops working whatsoever with `lua: test.lua:1: module 'iuplua' not found: no field package.preload['iuplua']`. I added my variables to the question. – Sun of A beach Mar 01 '23 at 13:54

2 Answers2

1

In short, when require'iuplua', lua will try to open the luaopen_iuplua function in the file.

If the loading method is changed to require'iup.iuplua', it will try to open the luaopen_iup_iuplua function in the file, which does not exist in the file, so it will error

One solution is to add a line of statement before executing the require: package.cpath = package.cpath .. 'iup/?.dll'

Another option is to open the DLL with package.loadlib('iup/iuplua.dll', 'luaopen_iuplua').

绒梦唯
  • 11
  • 1
0

Eventually, I just dropped all the dlls into bin folder with lua.exe and lua54.dll. Added following paths to my LUA_CPATH system variable:

C:\lua-5.4.4\bin\?.dll
C:\lua-5.4.4\bin\?54.dll

As much as I don't like having all IUPLua binaries in the same folder with Lua binaries, it seems it's the only way to do it.

Also, I can require iuplua in the modern way like that: local anyname = require 'iuplua', but all other modules like iupluacontrols or iuplua_plot must be called in the old way: require 'iupluacontrols' and require 'iuplua_plot'. Then all functions from loaded modules are available in anyname table.

Sun of A beach
  • 171
  • 1
  • 10