I tried to follow the example at http://www.keplerproject.org/luasql/examples.html
Lua 5.2.0 Copyright (C) 1994-2011 Lua.org, PUC-Rio
> require "luasql.postgres"
> env = assert (luasql.postgres())
stdin:1: attempt to index global 'luasql' (a nil value)
stack traceback:
stdin:1: in main chunk
[C]: in ?
>
What am I missing?
You could try
luasql = require "luasql.postgres"
env = assert (luasql.postgres())
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
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'm getting this error when trying to require LuaSocket with Lua5.3
error loading module 'socket.core' from file
'/usr/local/lib/lua/5.3/socket/core.so':
/usr/local/lib/lua/5.3/socket/core.so: undefined symbol: luaL_openlib
Console Output with demonstration:
barreeeiroo#Telegram ~/mattata-ai> lua
Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio
> local socket = require("socket.core")
> ^C⏎
barreeeiroo#Telegram ~/mattata-ai> lua5.3
Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio
> local socket = require("socket.core")
error loading module 'socket.core' from file '/usr/local/lib/lua/5.3/socket/core.so':
/usr/local/lib/lua/5.3/socket/core.so: undefined symbol: luaL_openlib
stack traceback:
[C]: in ?
[C]: in function 'require'
stdin:1: in main chunk
[C]: in ?
> ^C⏎
barreeeiroo#Telegram ~/mattata-ai> readelf -a /usr/bin/lua | grep openlib
109: 0000000000018a70 163 FUNC GLOBAL DEFAULT 15 luaL_openlib##LUA_5.2
240: 0000000000018b20 117 FUNC GLOBAL DEFAULT 15 luaL_openlibs##LUA_5.2
barreeeiroo#Telegram ~/mattata-ai> readelf -a /usr/bin/lua5.3 | grep openlib
238: 000000000001b330 85 FUNC GLOBAL DEFAULT 15 luaL_openlibs##LUA_5.3
How can I make luaL_openlib to work with Lua5.3?
I faced the same issue and solved with this link: https://luarocks.org/
My problem is that I was using lua 5.3 and my luarocks was downloading modules for lua 5.1
I tried this code :
assert(os.setlocale('fr_FR'))
print(12.34)
And it failed.
locale.lua
lua: locale.lua:1: assertion failed!
stack traceback:
[C]: in function 'assert'
locale.lua:1: in main chunk
[C]: in ?
On Ubuntu 14.04, lua -v
Lua 5.2.3 Copyright (C) 1994-2013 Lua.org, PUC-Rio
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.