Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

With

ConTeXt  ver: 2010.05.24 13:05 MKIV  fmt: 2010.12.18  int: english/english

the ConTeXt code

\starttext
   \message{one}
   \directlua{print(1)}
   \message{two}
   \usercode{print(2)}
\stoptext

gives (excerpted)

systems         : begin file minex.tex at line 1
one1
 two
! LuaTeX error <private user instance>:1: attempt to call global 'print' (a nil value)
stack traceback:
        <private user instance>:1: in main chunk.
\usercode #1->\directlua 1{protect("userdata")#1}

l.5    \usercode{print(2)}

This I interpret as the print variable being bound in the usual way to the Lua basic function in the default namespace, but unbound in Context's user namespace; likewise all the other basic Lua functions that I checked are unbound in the user namespace.

Is this behaviour intended?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

The normal globals are inside the table global within usercode:

\starttext
   \usercode{global.print(2)}
\stoptext
share|improve this answer
    
Yes, I've got my code to work, thank you. This isn't want the Programming in LuaTeX wiki page says: it says global contains "all the Lua functions defined by ConTeXt (but not the inbuilt Lua functions)"; additionally many tables (they're not "normal" globals?) are in the user namespace, such as stdin, tex - is this documented fully anywhere? –  Charles Stewart Apr 27 '11 at 13:19
    
@Charles: I wrote the Programming in Lua page. IIRC, some of this was documented in the MkIV manual, some in the source code; rest I figured from trial and error. I will check if something changed recently or if I was wrong from the beginning and appropriately modify the page. The page needs an overhaul anyways (no mention of \ctxcommands and family, linking to the cld page, etc). –  Aditya Apr 27 '11 at 15:00
    
@Aditya: It was enough to get started, thank you! The version of the Mk IV manual that I looked at (probably not up-to-date) seems rather impressionistic on this. –  Charles Stewart Apr 27 '11 at 16:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.