ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Loading lua file.
@ 2012-12-13  0:43 Andre Caldas
  2012-12-13  2:01 ` Philipp Gesang
  0 siblings, 1 reply; 4+ messages in thread
From: Andre Caldas @ 2012-12-13  0:43 UTC (permalink / raw)
  To: ConTeXt users

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.
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Loading lua file.
  2012-12-13  0:43 Loading lua file Andre Caldas
@ 2012-12-13  2:01 ` Philipp Gesang
  2012-12-13 14:52   ` Andre Caldas
  0 siblings, 1 reply; 4+ messages in thread
From: Philipp Gesang @ 2012-12-13  2:01 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1664 bytes --]

Hey André,

···<date: 2012-12-12, Wednesday>···<from: Andre Caldas>···

> 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

[-- Attachment #1.2: Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Loading lua file.
  2012-12-13  2:01 ` Philipp Gesang
@ 2012-12-13 14:52   ` Andre Caldas
  2012-12-14  9:56     ` Procházka Lukáš Ing. - Pontex s. r. o.
  0 siblings, 1 reply; 4+ messages in thread
From: Andre Caldas @ 2012-12-13 14:52 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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.
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Loading lua file.
  2012-12-13 14:52   ` Andre Caldas
@ 2012-12-14  9:56     ` Procházka Lukáš Ing. - Pontex s. r. o.
  0 siblings, 0 replies; 4+ messages in thread
From: Procházka Lukáš Ing. - Pontex s. r. o. @ 2012-12-14  9:56 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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 <andre.em.caldas@gmail.com> wrote:

> 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

___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-12-14  9:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-13  0:43 Loading lua file Andre Caldas
2012-12-13  2:01 ` Philipp Gesang
2012-12-13 14:52   ` Andre Caldas
2012-12-14  9:56     ` Procházka Lukáš Ing. - Pontex s. r. o.

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).