Hello my wise masters of the Force and teachers of Jedi...
It seems that my first module (SCANCSV of scancsv.lua library of CTM in
Brejlov) work without any visible errors (without
documentation and with a junkyard yet), but I'm not sure whether is there a
hidden problem or future collisions. Therefore I have a few of questions
for
modules namespaces, luacode namespaces etc. I want to ask how relates a
namespace ConTeXt module with
namespace of Lua code, which is listed within this module and others
questions.
1. Is the namespace of Lua code independent of the namespace module?
2. If are ConTeXt macros defined in the module, are automatically in its
namespace?
3. Can both namespaces (module and Luacode) somehow connected?
4. What happens when I have two macros with the same name in two
different modules?
5. Can I call the macros of the same names in different namespaces
(diferent modules)?
6. Can I read about somewhere more?
7. I enclose below a minimal example of the module (I do not know why
there are some things) to comment or write yours comments and
suggestions, etc.
I'd like to start with something simpler, but this is the reality of our
Empire....
Thanks everyone for the advice or recommendations for the study.
Greetings
Jarda Hajtmar
My minimal example ..
% ************************** BEGIN MODULE
******************************************
%D \module
%D [ file=t-moduleexample,
%D version=2010.09.27,
%D title=\CONTEXT\ User Module,
%D subtitle=Module example,
%D author=Author Name,
%D date=\currentdate,
%D copyright=Copyright,
%D email=mailaddress(a)domain.com,
%D license=Public Domain]
%D \section{Title}
%D This is modul is intended for ...
%D The following option are availabe:
%D
%S B
%S Everything onwards is
%S skipped and does not
%S appear in the PDF.
%S E
\writestatus{loading}{ConTeXt User Module / Module example}
\unprotect
\startinterface all
\setinterfacevariable {moduleexample} {moduleexample}
\stopinterface
\definenamespace
[moduleexample]
[type=module,
comment=Module example,
version=1,
name=moduleexample,
style=yes,
command=yes,
setup=list,
parent=moduleexample]
\startluacode
thirddata = thirddata or { }
thirddata.moduleexample = {
gVar1='xxxx', -- comment
gVar2='yyyyy', -- comment
-- etc...
}
function thirddata.moduleexample.myfirstfunction(parameter)
local locvar=parameter
tex.print("Input parameter : "..locvar)
thirddata.moduleexample.gVar1=locvar
return locvar
end
function thirddata.moduleexample.mysecondfunction()
tex.print("Output parameter: "..thirddata.moduleexample.gVar1)
end
\stopluacode
\def\myfirstmodulemacro#1{\ctxlua{thirddata.moduleexample.myfirstfunction("#1")}}
\def\mysecondmodulemacro{\ctxlua{thirddata.moduleexample.mysecondfunction()}}
\protect \endinput
% ************************** END MODULE
******************************************
% ************************** BEGIN USING MODULE
******************************************
\usemodule[t-moduleexample]
\starttext
\myfirstmodulemacro{Hello World!}
\mysecondmodulemacro
\stoptext
% ************************** END USING MODULE
******************************************