I'm Trying to import sockets in a lua script to make a twitch chat app inside a game.
The game implementation of lua is "Designed to work with OpenResty’s fork of LuaJIT, with LuaJIT compiled with 5.2 compatibility option." (https://github.com/ac-custom-shaders-patch/acc-lua-sdk/)
I am not familiar with lua but I have been trying to get this to work for a few days but with not much progress.
I have tried different repositories with sockets/websockets but could not get them to work.
when trying local socket = require("socket") I get the following error
[
module 'socket.core' not found: no field package.preload['socket.core']
no file '\socket\core.lua'
no file 'E:\steam\SteamApps\common\assettocorsa\ua\socket\core.lua'
no file 'E:\steam\SteamApps\common\assettocorsa\Jua\socket\core\init.lua'
no file 'C:\Program Files (x86)\Lua\5.1\Jua\socket\core.luac'
no file 'E:\steam\SteamApps\common\assettocorsa\apps\lua\My FirstApp/socket\core.lua'
no file 'E:\steam\SteamApps\common\assettocorsa\extension/internal/lua-socket\core.lua'
no file '\socket\core.dil'
no file 'E:\steam\SteamApps\common\assettocorsa\socket\core.dil'
no file 'E:\steam\SteamApps\common\assettocorsa\Vloadall.dll'
no file '.\socket.dll'
no file 'E:\steam\SteamApps\common\assettocorsa\socket.dll'
no file 'E:\steam\SteamApps\common\assettocorsa\loadall.dll' [C]: in function 'require
...mApps\common\assettocorsa\apps\lua\My FirstApp/socket.lua:12: in main chunk [C]: in function 'require'
...s\common\assettocorsa\apps\lua\My FirstApp\MyFirstApp.lua:13: in main chunk
][1]
If I understood this correctly that socket.core is normally something included in the lua language that would be installed on the machine. But I need this to be included with the app so it can be shared to other people as well.
From my understanding I need something made for lua 5.1 and compiled for windows. The game runs in 64bits by default but can be forced to 32 bits so i'm assuming ideally i'd need 2 dlls.
This is mostly why I've been trying hard to get this particular solution (https://github.com/luapower/socket) to work as they include pre build dlls which I'm assuming contain everything needed for socket to run. But I can't get the error above to go away.
I have also not been able to build my own dll due to my lack of understanding of lua and programming in general and more importantly i'm not sure what to build exactly to make sure it would work for this particular usecase.
The whole lua stuff seems to be super unfriendly to use on windows in general which only adds to my confusion so any insight on how I could proceed to get this to work would be greatly appreciated. I can supply further info neeeded.
edit: it seems that my understanding of where require was looking for files was wrong. I've moved the files to a separate folder and I now get Error: error loading module socket.core' from file '.\socket\core.dll: %1 is not a valid Win32 application. [C]: at 0x7ffd961fb3c0 [C]: in function 'require' ...s\common\assettocorsa\apps\lua\MyFirstApp\MyFirstApp.lua:16: in main chunk
So I guess it's running lua in 32 bits? I tried to grab some compiled socket/core.dll from diff repos and they all give the error.. I checked with dependency walker and some were 32 bits and others were 64bits dlls. Same error regardless.
[1]: https://i.stack.imgur.com/Mdexh.png
Note that there are no commits in [GitHub]: luapower/socket since Nov 2019. Also, the directory structure doesn't seem correct. And (something that should have been mentioned there) it was built (and runs) with Lua 5.1.
I've built v3.0.0 and placed the binaries at: [GitHub]: CristiFati/Prebuilt-Binaries - (master) Prebuilt-Binaries/LuaSocket/v3 (built with Lua 5.4.4 from the same repository, which should be used to run it).
Here's an example:
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q071876058]> sopr.bat
### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ###
[prompt]> "c:\Program Files\Lua\Lua\5.4.4\bin\lua.exe" -l socket
c:\Program Files\Lua\Lua\5.4.4\bin\lua.exe: module 'socket' not found:
no field package.preload['socket']
no file 'c:\Program Files\Lua\Lua\5.4.4\bin\lua\socket.lua'
no file 'c:\Program Files\Lua\Lua\5.4.4\bin\lua\socket\init.lua'
no file 'c:\Program Files\Lua\Lua\5.4.4\bin\socket.lua'
no file 'c:\Program Files\Lua\Lua\5.4.4\bin\socket\init.lua'
no file 'c:\Program Files\Lua\Lua\5.4.4\bin\..\share\lua\5.4\socket.lua'
no file 'c:\Program Files\Lua\Lua\5.4.4\bin\..\share\lua\5.4\socket\init.lua'
no file '.\socket.lua'
no file '.\socket\init.lua'
no file 'c:\Program Files\Lua\Lua\5.4.4\bin\socket.dll'
no file 'c:\Program Files\Lua\Lua\5.4.4\bin\..\lib\lua\5.4\socket.dll'
no file 'c:\Program Files\Lua\Lua\5.4.4\bin\loadall.dll'
no file '.\socket.dll'
stack traceback:
[C]: in function 'require'
[C]: in ?
[prompt]>
[prompt]> set LUA_PATH=;;c:\Program Files\LunarModules\LuaSocket\3.0.0(Lua5.4)\?.lua
[prompt]> set LUA_CPATH=;;c:\Program Files\LunarModules\LuaSocket\3.0.0(Lua5.4)\?.dll
[prompt]>
[prompt]> "c:\Program Files\Lua\Lua\5.4.4\bin\lua.exe" -l socket
Lua 5.4.4 Copyright (C) 1994-2022 Lua.org, PUC-Rio
> -- Lua started, meaning the module was successfully loaded
> ^Z
[prompt]> :: Attempt to load the module in Lua 32bit (pc032)
[prompt]> "c:\Program Files (x86)\Lua\Lua\5.4.4\bin\lua.exe" -l socket
c:\Program Files (x86)\Lua\Lua\5.4.4\bin\lua.exe: error loading module 'socket.core' from file 'c:\Program Files\LunarModules\LuaSocket\3.0.0(Lua5.4)\socket\core.dll':
%1 is not a valid Win32 application.
stack traceback:
[C]: in ?
[C]: in function 'require'
...am Files\LunarModules\LuaSocket\3.0.0(Lua5.4)\socket.lua:12: in main chunk
[C]: in function 'require'
[C]: in ?
[prompt]> :: Module structure
[prompt]> tree /a /f "c:\Program Files\LunarModules\LuaSocket\3.0.0(Lua5.4)"
Folder PATH listing for volume SSD0-WIN
Volume serial number is 0000001F F2CE:FA29
C:\PROGRAM FILES\LUNARMODULES\LUASOCKET\3.0.0(LUA5.4)
| ltn12.lua
| LuaSocket.LICENSE
| mbox.lua
| mime.lua
| socket.lua
|
+---mime
| core.dll
|
\---socket
core.dll
ftp.lua
headers.lua
http.lua
smtp.lua
tp.lua
url.lua
As seen, I also covered the pc064 / pc032 .dll mismatch. For more details, check [SO]: Python Ctypes - loading dll throws OSError: [WinError 193] %1 is not a valid Win32 application (#CristiFati's answer).
I wrote some code. and fixed some errors with the help of good persons.
Now, this utility(samChecker-exe.exe) works properly in Stack environment.
This utility use text-icu and I coded this utility on windows. Of course, I want to work this utility on other windows OS.
I copied %stackPath%.stack-work\install\~\bin\samCheceker-exe.exe to some other folder, and execution through CMD.
But I got error message that says "libicuuc57.dll dose not exist. so program can't start. please re-install the program."
I copied libicuuc57.dll, and so... as like programming newbies, but failed. "stack install" command was the same result.
(I installed text-icu and installed ICU lib. on windows. The input file encoded in "MS949")
With help of Francesco Ariis from (beginners#haskell.org), I stepped forward.
But still got error message.
C:\Users\shaeg\Documents\Haskell\samChecker3> stack build --ghc-options="-static -optl-static"
Warning: File listed in samChecker3.cabal file does not exist: README.md
samChecker3-0.1.0.0: unregistering (local file changes: app\Main.hs samChecker3.cabal src\Lib.hs test\Spec.hs)
samChecker3-0.1.0.0: configure (lib + exe)
Configuring samChecker3-0.1.0.0...
samChecker3-0.1.0.0: build (lib + exe)
Preprocessing library samChecker3-0.1.0.0...
[1 of 1] Compiling Lib ( src\Lib.hs, .stack-work\dist\ca59d0ab\build\Lib.o )
Preprocessing executable 'samChecker3-exe' for samChecker3-0.1.0.0...
[1 of 1] Compiling Main ( app\Main.hs, .stack-work\dist\ca59d0ab\build\samChecker3-exe\samChecker3-exe-tmp\Main.o )
Linking .stack-work\dist\ca59d0ab\build\samChecker3-exe\samChecker3-exe.exe ...
C:/Users/shaeg/AppData/Local/Programs/stack/x86_64-windows/ghc-8.0.2/mingw/bin/ld.exe: cannot find -licuuc
C:/Users/shaeg/AppData/Local/Programs/stack/x86_64-windows/ghc-8.0.2/mingw/bin/ld.exe: cannot find -licuin
C:/Users/shaeg/AppData/Local/Programs/stack/x86_64-windows/ghc-8.0.2/mingw/bin/ld.exe: cannot find -licudt
collect2.exe: error: ld returned 1 exit status
`gcc.exe' failed in phase `Linker'. (Exit code: 1)
Warning: File listed in samChecker3.cabal file does not exist: README.md
-- While building package samChecker3-0.1.0.0 using:
C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_1.24.2.0_ghc-8.0.2.exe --builddir=.stack-work\dist\ca59d0ab build lib:samChecker3 exe:samChecker3-exe --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
[stack path] results
extra-include-dirs: C:\Users\shaeg\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\include
extra-library-dirs: C:\Users\shaeg\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\lib
According to first error message(libicuuc57.dll dose not exist. so program can't start. please re-install the program.), I find the path for libicuuc57.dll, and re-set the extra-library-dirs.
C:\Users\shaeg\Documents\Haskell\samChecker3>stack build --extra-lib-dirs=C:\Users\shaeg\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\bin --ghc-options="-static -optl-static"
But got the same result.
libicuuc75.dll, libicuin57.dll etc files is located in C:\Users\shaeg\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\bin
Someones says, this is Linker Acting.
How can I fix this error?
Thank you so much.
Sincerely, S. Chang.
Here is my stack path.
C:\Users\shaeg\Documents\Haskell\samChecker3>stack path
stack-root: C:\sr
project-root: C:\Users\shaeg\Documents\Haskell\samChecker3
config-location: C:\Users\shaeg\Documents\Haskell\samChecker3\stack.yaml
bin-path: .;C:\sr\snapshots\7dd4ddea\bin;C:\Users\shaeg\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin;C:\Users\shaeg\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\mingw\bin;C:\Users\shaeg\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\bin;C:\Users\shaeg\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\usr\bin;C:\Users\shaeg\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\usr\local\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\IntelSGXPSW\bin\x64\Release\;C:\Program Files\Intel\IntelSGXPSW\bin\win32\Release\;c:\Program Files\Intel\WiFi\bin\;c:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Hewlett-Packard\SimplePass\;C:\Users\shaeg\AppData\Roaming\local\bin;C:\Users\shaeg\AppData\Local\Microsoft\WindowsApps
programs: C:\Users\shaeg\AppData\Local\Programs\stack\x86_64-windows
compiler-exe: C:\Users\shaeg\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc.EXE
compiler-bin: C:\Users\shaeg\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin
local-bin: C:\Users\shaeg\AppData\Roaming\local\bin
extra-include-dirs: C:\Users\shaeg\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\include
extra-library-dirs: C:\Users\shaeg\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\lib
snapshot-pkg-db: C:\sr\snapshots\7dd4ddea\pkgdb
local-pkg-db: C:\Users\shaeg\Documents\Haskell\samChecker3\.stack-work\install\02136e14\pkgdb
global-pkg-db: C:\Users\shaeg\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\lib\package.conf.d
ghc-package-path: C:\Users\shaeg\Documents\Haskell\samChecker3\.stack-work\install\02136e14\pkgdb;C:\sr\snapshots\7dd4ddea\pkgdb;C:\Users\shaeg\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\lib\package.conf.d
snapshot-install-root: C:\sr\snapshots\7dd4ddea
local-install-root: C:\Users\shaeg\Documents\Haskell\samChecker3\.stack-work\install\02136e14
snapshot-doc-root: C:\sr\snapshots\7dd4ddea\doc
local-doc-root: C:\Users\shaeg\Documents\Haskell\samChecker3\.stack-work\install\02136e14\doc
dist-dir: .stack-work\dist\ca59d0ab
local-hpc-root: C:\Users\shaeg\Documents\Haskell\samChecker3\.stack-work\install\02136e14\hpc
local-bin-path: C:\Users\shaeg\AppData\Roaming\local\bin
ghc-paths: C:\Users\shaeg\AppData\Local\Programs\stack\x86_64-windows
I was able to test it recently, and share my solution.
First of all, I assume environment of latest msys2 which is installed mingw64/mingw-w64-x86_64-icu 57.1-2 package.
Dynamic linking
Executable which dynamically linked has dependencies to libgcc_s_seh-1.dll libicudt57.dll libicuin57.dll libicuuc57.dll libstdc++-6.dll libwinpthread-1.dll under stack's msys2 mingw64/bin path. If you have already built dynamic linked executable, copying all of them to same directory will solve the problem.
Dependency walker in my comment can help to reveal all of these dependencies.
Static linking
Currently text-icu package doesn't seem to support static linking. So we should modify it ourselves. If you don't know how to make it into local package, note the third option of this.
Modify text-icu-0.7.0.1's .cabal file extra-libraries section to the following.
extra-libraries: sicuin sicuuc sicudt
-- if os(mingw32)
-- extra-libraries: icuin icudt
-- else
-- extra-libraries: icui18n icudata
Append -pgmlC:\Users\[USERNAME]\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\mingw\bin\g++.exe to your executable's ghc-options cabal entry. This is required to link to ICU's C++ symbols.
Then just do stack build.
After overcoming some troubles with installation I tried to use erlang debugger on simple module:
I included -compile([debug_info]). option in source file and compiled with:
1> c(test_module).
This did not work as expected: After running
2> debugger:start().
the monitor window appeared, then I clicked
Module->Interpret...->test_module.erl
and got error
"Error when interpreting: test_module.erl: No debug_info in BEAM file".
Deleting -compile([debug_info]). line and changing
1> c(test_module).
to
1> c(test_module, [debug_info]).
solved the problem.
What is the difference between these two ways of setting compilation option, why one works and the other does not?
According to the docs, the two ways should be equivalent:
Note that all the options except the include path ({i,Dir}) can also
be given in the file with a -compile([Option,...]). attribute.
(From Erlang -- compile doc)
Check this question for more info.
I'm going over a very basic erlang book while using yaws. I'm editing a single yaws file and refreshing the browser. Often (3rd time now) the process will just start to show this error. and i look and look for a syntax error or anything, and eventually i just restart the process and everything works. without any change to the source file.
right now this is the source file that triggered the error this last time
<erl>
out(Arg) ->
{ehtml,
{table, [{width, "100%"}],
{tr,[],
[{td, [{width, "50%"}], "hello world!"},
{td, [{width, "50%"}], "hi again."}]
}
}
}.
</erl>
I tried searching the error, but where all the search results have a meaningful context like "no access" all i get is "<<>>"
=ERROR REPORT==== 26-Nov-2013::20:17:32 ===
Yaws process died: {{badmatch,<<>>},
[{yaws_server,skip_data,2,
[{file,"yaws_server.erl"},{line,2951}]},
{yaws_server,deliver_dyn_file,6,
[{file,"yaws_server.erl"},{line,2717}]},
{yaws_server,aloop,4,
[{file,"yaws_server.erl"},{line,1152}]},
{yaws_server,acceptor0,2,
[{file,"yaws_server.erl"},{line,1013}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]}
Some version info:
Yaws 1.94
Debian GNU/Linux 7.2 (wheezy)
Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64 GNU/Linux
Erlang R15B01 (erts-5.9.1) [source] [64-bit] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false]
Any ideas what this is telling me?
Also, any suggestions for debuggers that are good for beginners is very welcome.
For debugging, I think using Erlang tracing will be helpful. We want to figure out why the yaws_server:skip_data/2 function would be getting a badmatch exception, and specifically why it's getting an empty binary passed to it as that's the only way it could encounter that error. So we need to trace that condition. Try these steps (and don't forget the trailing period on each Erlang shell command):
Run yaws in interactive mode: yaws -i
Once yaws comes up, hit enter to get an Erlang shell prompt.
Create a tracing function for dbg so we get a reasonably formatted backtrace from the trace data: F = fun({trace,_,_,_,Dump},[]) -> io:format("~s~n", [binary_to_list(Dump)]), [] end.
Turn on tracing with this command: dbg:tracer(process, {F, []}).
Trace calls in all processes: dbg:p(all, call).
Now trace the condition of yaws_server:skip_data/2 getting an empty binary as a first argument, and when it does, get a backtrace:
dbg:tpl(yaws_server,skip_data,dbg:fun2ms(fun([<<>>, _]) -> message(process_dump()) end)).
With this in place, start hitting your .yaws page until you provoke the condition, at which point a backtrace will be displayed in your Erlang shell. If you get that backtrace, please copy it into a gist or pastebin and post a link to it as a follow-up here.
If I am correct the output of the out function is supposed to be a list. I didn't check your whole code but the following should work:
<erl>
out(Arg) ->
[{ehtml,
{table, [{width, "100%"}],
{tr,[],
[{td, [{width, "50%"}], "hello world!"},
{td, [{width, "50%"}], "hi again."}]
}
}
}].
</erl>
If I want to know if erlang was compiled with ssl support I do :
1> ssl:versions().
But how to view the list of available application that were included at compilation time ? I need to as access to the list to include it in an installation checklist.
Thanks to all
You can use application module to do this:
$ erl
Erlang R15B03 (erts-5.9.3.1) [source] [64-bit] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false] [dtrace]
Eshell V5.9.3.1 (abort with ^G)
1> application:which_applications().
[{stdlib,"ERTS CXC 138 10","1.18.3"},
{kernel,"ERTS CXC 138 10","2.15.3"}]