Luac: read version 1280.1; expected at most 80.1 - lua

I try to load a .lc file that I compiled with luac beforehand:
print("Hello World!")
and
luac -o helloworld.lc helloworld.lua
in order to get the compilation. However, as I am importing that module I am getting:
\lua\ai\helloworld.lc too new: read version 1280.1; expected at most 80.1
This is my luac -v
E:\lua\lua-5.0.3\bin>luac -v
Lua 5.0.3 Copyright (C) 1994-2006 Tecgraf, PUC-Rio
The game I am modding is actually using Lua 5.0 which is why I don't really understand why I am seeing this error..

Related

Cannot install FFI library for Lua/LuaJIT

I have already correctly installed Lua, LuaJIT and Luarocks (I can run each of them in the terminal without any errors too). I'm trying to run the command luarocks install luaffi but it is returning an error
Error: No results matching query were found for Lua 5.4
To check if it is available for other Lua versions, use --check-lua-versions.
So I tried running luarocks install luaffi --check-lua-versions which also returns the following:
Checking if available for other Lua versions...
Checking for Lua 5.1...
Checking for Lua 5.2...
Checking for Lua 5.3...
Error: No results matching query were found for Lua 5.4.
luaffi is not available for any Lua versions. "
I'm completely lost, I cannot use ffi in my code because of this (It returns module "ffi" not found).
After the build (See: https://github.com/zhaozg/lua-ffi ) you can use Lua 5.1 to test it.
€ cat luajit_sleep.lua
--[[
Lua JIT ffi Example - Implementing a Lua sleep() function from C
]]
local ffi = require("ffi")
ffi.cdef[[void Sleep(int ms); int poll(struct pollfd *fds, unsigned long nfds, int timeout);]]
local sleep
if ffi.os == "Windows" then
function sleep(s) ffi.C.Sleep(s*1000) end
else
function sleep(s) ffi.C.poll(nil, 0, s*1000) end
end
return sleep
€ /bin/lua
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
> sleep = require('luajit_sleep')
> sleep(1) -- CPU friendly sleep() function :-)
It uses (lsof | grep lua)...
/usr/local/lib/lua/5.1/ffi.so
EDIT - Found the Command to install: https://luarocks.org/modules/colesbury/luaffi
Do: luarocks install --server=https://luarocks.org/dev luaffi --verbose
Also goes to...
os.execute: chmod '0755' '/usr/local/lib/lua/5.1/ffi.so'
Results: 1
1 (number): 0
luaffi scm-1 is now installed in /usr/local (license: BSD)

Why does formatting a number round differently in LuaJIT vs. Lua?

Using string.format() (which supposedly defers to C's sprintf())) to format a number in LuaJIT rounds differently than every other Lua interpreter I've tried:
$ lua -v
Lua 5.4.1 Copyright (C) 1994-2020 Lua.org, PUC-Rio
$ lua -e 'print(string.format("%.4f", 32.90625))'
32.9062
$ luajit -v
LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2020 Mike Pall. http://luajit.org/
$ luajit -e 'print(string.format("%.4f", 32.90625))'
32.9063
Why does this happen and how can I‌ make it stop? I'd like to tell LuaJIT to round the same direction every other Lua interpreter does.

Why is Lua reporting that "The specified procedure could not be found." for this library compiled from source?

I've been working at this for a while now and I can't figure out what's wrong.
At this point I've built everything from source and it still doesn't work. My environment is Windows 10 x64 and I'm compiling with Cygwin's MinGW-w64. Everything is compiled as i686 (32-bit) and not x86_64.
For reference, instances where I use gcc is actually i686-w64-mingw32-gcc. liblua53.dll.a and libyaml.a were compiled from source using Lua 5.3.5 and LibYAML 0.2.2.
I built the objects:
gcc -DVERSION=\"git-5695363\" -Ilua-5.3/src -Ilibyaml/src/include -c ext/yaml/emitter.c -o emitter.o
gcc -DVERSION=\"git-5695363\" -Ilua-5.3/src -Ilibyaml/src/include -c ext/yaml/scanner.c -o scanner.o
gcc -DVERSION=\"git-5695363\" -Ilua-5.3/src -Ilibyaml/src/include -c ext/yaml/parser.c -o parser.o
gcc -DVERSION=\"git-5695363\" -Ilua-5.3/src -Ilibyaml/src/include -c ext/yaml/yaml.c -o yaml.o
Then linked:
gcc -shared -static -s -Llua-5.3/dist -Llibyaml/dist emitter.o parser.o scanner.o yaml.o -lyaml -llua53.dll -o lyaml.dll
I've linked it as -shared because the output is a dll and as -static because I'm statically linking libyaml.a. I also tried compiling with dynamic linking to libyaml.dll with the same error from Lua.
My Lua environment was compiled from the source and compiler:
> lua53.exe -v
Lua 5.3.5 Copyright (C) 1994-2018 Lua.org, PUC-Rio
Running a simple script works fine:
> lua53.exe -e 'print("Hello!")'
Hello!
But I can't load the library:
> lua53.exe -e 'require("lyaml")'
lua53.exe: error loading module 'lyaml' from file 'lyaml.dll':
The specified procedure could not be found.
stack traceback:
[C]: in ?
[C]: in function 'require'
(command line):1: in main chunk
[C]: in ?
I know that this is an error from Windows but I don't know what procedure is missing or where it's coming from.
I also checked that all dynamic-linking dependencies are being met and functions are being exported:
How can I debug this further?
I ended up building everything on Linux and ran into the same problem but with a much more useful error:
$LD_LIBRARY_PATH=. ./test.lua
/bin/lua: error loading module 'lyaml' from file './lyaml.so':
./lyaml.so: undefined symbol: luaopen_lyaml
stack traceback:
[C]: in ?
[C]: in function 'require'
./test.lua:5: in main chunk
[C]: in ?
The problem is that Lua binds the "luaopen_" symbol to the name of the library being loaded. So require("somelib") would be for somelib.dll with a an exact-matching luaopen_somelib export symbol. I built the library as lyaml.dll (to match the library name) but this symbol was exported as luaopen_yaml, which meant that Lua was looking for luaopen_lyaml (which didn't exist).
Several solutions are possible:
Modify the export in the source code to match the file name.
Modify the file name to match the export from the source code.
Ignore the discrepancy completely and use package.loadlib() which allows this.
I've opted for the third solution. Thank you #PaulKulchenko for the third solution.
The key takeaway from this is that there is by default a tight coupling between require(), the export symbol, and the file name of library being loaded.
Since you are already using Dependency walker, I recommend using its "Profile" feature. You can start profiling on lua53.exe file and when you execute the require command, the profiler will show you the trace of all DLLs being loaded and any errors related to their load as well as the details of the error that you don't see from the Lua message.
You can also execute package.loadlib("lyaml.dll", "luaopen_yaml") to confirm that the signature is valid; you should get a function back that, when executed, will return the actual package.

can't install this file (mercury6_2.for) with gfortran

I tried this:
Alan#Alan ~/mercury
$ gfortran -o mercury6_2.for
gfortran.exe: fatal error: no input files; unwilling to write output files
compilation terminated
and:
Alan#Alan ~/mercury
$ gfortran -o mercury mercury6_2.for
gfortran.exe: error: CreateProcess: No such file or directory
My file exist:
Alan#Alan ~/mercury
$ ls
big.in element.in mercury.inc mercury6_2.for README.txt
close.in element6.for mercury6.man message.in small.in
close6.for files.in mercury6.tar param.in swift.incenter code here
gfortran seems to be running in Cygwin:
Alan#Alan ~/mercury
$ gfortran --version
GNU Fortran (GCC) 4.8.0 20130302 (experimental) [trunk revision 196403]
Copyright (C) 2013 Free Software Foundation, Inc.
GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING
So I don't know.
Is there away that I could do this differently?

Create a new file in Lua/LuaFileSystem

I've looked over the Lua & LuaFileSystem Docs and have yet to find a way to create a new file, I also scouted around on here but to the same end.
As a note, the solution I'm looking for has to be OS neutral to ensure portability, but I'm happy to get different answers for different systems.
Example (writing "Hello World" into test.txt):
$ lua
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> file = io.open("test.txt", "w")
> file:write("Hello World")
> file:close()
> ^D
$ cat test.txt
Hello World
See also: Lua IO tutorial

Resources