Package imakeidx tests for \directlua before using \luatexversion:
\ifdefined\directlua
However after package pgfplots is loaded the command \directlua is defined with meaning \relax.
The problem is in the file TDS:tex/generic/pgfplots/util/pgfplotsutil.code.tex
and also
TDS:tex/generic/pgfplots/util/pgfplotsbinary.code.tex,
TDS:tex/generic/pgfplots/sys/pgflibrarypgfplots.surfshading.pgfsys-pdftex.def
are candidates, they contain:
\pgfutil@ifundefined{directlua}{%
The macro \pgfutil@ifundefined is defined in TDS:tex/generic/pgf/pgfutil-common.tex:
\long\def\pgfutil@ifundefined#1{%
\expandafter\ifx\csname#1\endcsname\relax
\expandafter\pgfutil@firstoftwo
\else
\expandafter\pgfutil@secondoftwo
\fi}
\def\pgfutil@firstoftwo#1#2{#1}
\def\pgfutil@secondoftwo#1#2{#2}
\csname has the side effect that it defines undefined commands with the meaning of \relax. If \pgfutil@ifundefined (also the same with LaTeX's \@ifundefined) is called,
\directlua gets defined with meaning \relax. In pgfplotsutil.code.tex this happens outside of groups.
Package imakeidx tests for \directlua and finds it defined, because it uses eTeX's
\ifdefined.
In my opinion pgfplots shouldn't use \pgfutil@ifundefined for macros that should remain undefined. A better variant is (name with camel case):
\def\pgfutil@IfUndefined#1{%
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname#1\endcsname\relax
\expandafter\pgfutil@firstoftwo
\else
\expandafter\pgfutil@secondoftwo
\fi
}
Then \csname and the test is called inside group and the meaning of the tested
command remains unchanged after the group. The disadvantage is that \pgfutil@IfUndefined is not expandable. But this does not matter in the use case here and many other uses cases in the package. Other macros are also affected (\@ifpackageloaded, \if@filesw, …). See also package ltxcmds that defines \ltx@ifundefined and ltx@IfUndefined that support e-TeX if available.
Package imakeidx could do a more conservative testing to additionally check
the command to be tested for the meaning \relax.
Workaround to fix the issue for the OP:
\usepackage{pgfplots}
\ifx\directlua\relax
\let\directlua\UnDeFiNeD
\fi
\usepackage{imakeidx}
Defining \luatexversion has the severe risk, that other packages might be confused.
Further remark to \pgfutil@ifundefined: \par tokens break \csname, therefore \long does not make any sense here. A better location for \long would be \pgfutil@firstoftwo and \pgfutil@secondoftwo, then their arguments might contain \par tokens (depending on the semantics of these two macros).
imakeidxhas reintroduced a malfunction caused bypgfplots. – egreg Oct 02 '12 at 20:53imakeidxis on the TeX Live servers; it should have corrected this issue and others due to bugs introduced in version 1.2 for which I apologize again. – egreg Oct 10 '12 at 15:45