$ lua -v -e "print(os.date('%l'))"
Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio
lua: (command line):1: bad argument #1 to 'date' (invalid conversion specifier '%l')
stack traceback:
[C]: in function 'date'
(command line):1: in main chunk
[C]: in
If so, where am I supposed to submit a bug report?
It's not a bug in Lua. os.date uses format, as described by strftime C function provided by your compiler (I mean the compiler that Lua was compiled with). It is known that some compilers (MSVC, for instance, which just outright crashes when provided with certain patterns) do not provide all patterns.
Related
You can execute a sequence of chunks by giving them all as arguments
to the stand-alone interpreter, with the -l option. For instance, if
you have a file a with a single statement x=1 and another file b with
the statement print(x), the command line
prompt> lua -la -lb
will run the chunk in a, then the one in b, which will print the
expected 1.
The above is from the following link: https://www.lua.org/pil/1.1.html. Yet, when I was trying it out, I got a syntax error.
So, in file a.lua, I have only one line, which is a=1. Then in file b.lua, I have also only one line print("the value of a is:",a) . Then,
:~$ lua -i -la -lb
Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio
the value of a is: true
>
:~$
:~$ lua -la -lb
the value of a is: true
Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio
>
Why did it print out "the value of a is: true"? rather than "the value of a is: 1"?
Any comments are greatly appreciated.
The error is because you are use a = 1 in your file a.lua, unlike in the example where a.lua contains x = 1 and b.lua contains print(x).
Using a rather then x means your using the same a variable being written to when -la completes, changing it to true.
This happens because the option -l name is equal to name = require("name"). When require completes, on a file that returns no result to it, require will return true.
your command lua -la -lb would look something like this to lua:
a = require("a") --this returning true after it completes
b = require("b") --this printing the value of `a` which will always be `true`
Sources:
Similar question answered on Lua-Users: command-line -l option issue
Egor Skriptunoff's Comment on this question
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.
Trying to run dump(x) macro example from http://lua-users.org/wiki/LuaMacros :
$ lua -lmacro
Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio
> __def 'dump(x) print(_STR(x).." = "..tostring(x))'
stdin:1: attempt to call global '__def' (a nil value)
stack traceback:
stdin:1: in main chunk
[C]: in ?
System: Cygwin x64.
Any ideas of what's wrong with __def? Thanks.
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..
I'm trying to load the Lua Augeas bindings using the Lua 5.1 standalone interpreter:
$ lua5.1
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
> require 'augeas'
error loading module 'augeas' from file '/usr/lib/x86_64-linux-gnu/lua/5.1/augeas.so':
/usr/lib/x86_64-linux-gnu/lua/5.1/augeas.so: undefined symbol: aug_close
stack traceback:
[C]: ?
[C]: in function 'require'
stdin:1: in main chunk
[C]: ?
>
$ nm -D /usr/lib/x86_64-linux-gnu/lua/5.1/augeas.so | grep close
U aug_close
Is there something I'm doing wrong?
The lua-augeas library in Ubuntu is an old version which was not built with the necessary flags to make link it to the Augeas library.