![](https://secure.gravatar.com/avatar/d15b29720cb36114018090f22cb39cb4.jpg?s=120&d=mm&r=g)
If I load a lua file from a module using \registerctxluafile{file}{1.001} or \ctxloadluafile{file} How can I be sure the file was in fact loaded? Can I make ConTeXt halt and issue an error in this case? Cheers, André Caldas.
![](https://secure.gravatar.com/avatar/e1d6b7d0f096cb8cf44273fa33fb05f0.jpg?s=120&d=mm&r=g)
Hey André,
···
If I load a lua file from a module using \registerctxluafile{file}{1.001} or \ctxloadluafile{file} How can I be sure the file was in fact loaded?
The related tracker output is quite comprehensive: \enabletrackers[resolvers.locating] \ctxloadluafile{sometest} it does not make Context terminate on fail, though.
Can I make ConTeXt halt and issue an error in this case?
the macros you cite don’t offer this behavior but you can easily write a wrapper for the file loader: % macros=mkvi \def\strictload[#fname]{% \directlua{ local success = environment.loadluafile[[#fname]] if not success then print[[unrecoverable error: could not load file #fname]] os.exit(1) end }% } \starttext \strictload[unknown] \stoptext Hth Philipp
Cheers, André Caldas. ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
-- () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments
![](https://secure.gravatar.com/avatar/d15b29720cb36114018090f22cb39cb4.jpg?s=120&d=mm&r=g)
Hello, Philipp!
If I load a lua file from a module using \registerctxluafile{file}{1.001} or \ctxloadluafile{file} How can I be sure the file was in fact loaded?
The related tracker output is quite comprehensive:
\enabletrackers[resolvers.locating] \ctxloadluafile{sometest}
Nice! Thank you. In my case, it was not being loaded because I had syntax errors in the lua file. The file was found, but not loaded. I guess it is a very good reason to halt! Cheers, André Caldas.
![](https://secure.gravatar.com/avatar/d6e7462bd4209f9c4cd08271985a50df.jpg?s=120&d=mm&r=g)
Hello,
I'm using this if loading failure is not fatal:
----
DoFile = function(fn)
return pcall(function() return dofile(fn) end)
end
DoFile("MyFile.lua") -- instead of 'dofile("MyFile.lua")'
----
You can play with handling error code (http://www.lua.org/manual/5.1/manual.html#pdf-pcall):
----
DoFile = function(fn)
local suc, res = pcall(function() return dofile(fn) end)
if suc then return res
else
-- Your handling code to come here
end
end
----
Best regards,
Lukas
On Thu, 13 Dec 2012 15:52:03 +0100, Andre Caldas
Hello, Philipp!
If I load a lua file from a module using \registerctxluafile{file}{1.001} or \ctxloadluafile{file} How can I be sure the file was in fact loaded?
The related tracker output is quite comprehensive:
\enabletrackers[resolvers.locating] \ctxloadluafile{sometest}
Nice! Thank you. In my case, it was not being loaded because I had syntax errors in the lua file. The file was found, but not loaded. I guess it is a very good reason to halt!
Cheers, André Caldas.
-- Ing. Lukáš Procházka [mailto:LPr@pontex.cz] Pontex s. r. o. [mailto:pontex@pontex.cz] [http://www.pontex.cz] Bezová 1658 147 14 Praha 4 Tel: +420 244 062 238 Fax: +420 244 461 038
participants (3)
-
Andre Caldas
-
Philipp Gesang
-
Procházka Lukáš Ing. - Pontex s. r. o.