TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


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

the ConTeXt code


gives (excerpted)

systems         : begin file minex.tex at line 1
! 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
up vote 4 down vote accepted

The normal globals are inside the table global within usercode:

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


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.