Hi Sergei,
This comes up a lot, and the solution really should be easier to find. On Wed, 28 Feb 2024, sergei.nau...@gmail.com wrote:
Hi!
I am new to LuaTeX and LuaLaTeX, please, bear with my ignorance of some probably basic things. :-) I need to get strings from MySQL database and the test Lua code that does it works fine when it is called from the command line:
You're probably looking for https://ctan.org/pkg/luapackageloader?lang=en Regards, Faheem Mitha
require("string") function projects_from_db () DBI = require("DBI") dbh = assert(DBI.Connect('MySQL','serge', 'serge', 'serge', 'localhost', 3306)) sth = assert(dbh:prepare('SELECT name,budget FROM projects')) sth:execute() for row in sth:rows() do print(string.format("%-55s & %7.1f \\\\",row[1],row[2])) end dbh:close() end -- projects_from_db() However, when I put it into latex file \usepackage{luacode} \usepackage{luapackageloader} \directlua{dofile('dbd.lua')} \newcommand{\projectsfromdb}{\luadirect{projects_from_db()}} It says that MySQL driver can not be found: ./DBI.lua:53: Cannot load driver MySQL. Available drivers are: (None) stack traceback: [C]: in function 'error' ./DBI.lua:53: in function 'DBI.Connect' dbd.lua:6: in function 'projects_from_db' [\directlua]:1: in main chunk. \luadirect ... { \luacode@maybe@printdbg {#1} #1 } l.64 \projectsfromdb Why is that? I checked package.cpath from Lua and the necessary path is there: Lua 5.3.6 Copyright (C) 1994-2020 Lua.org, PUC-Rio > package.cpath /usr/lib64/lua/5.3/?.so;/usr/lib64/lua/5.3/loadall.so;./?.so I tried to set a few environment variables: LUAROCKS_CPATH=/usr/lib64/lua/5.3 LUAROCKS_PATH=/usr/share/lua/5.3 but it did not make any difference -- Thanks, Sergei