Re: [NTG-context] Modules, namespaces, Luacode etc..

2010-10-01 Thread Jaroslav Hajtmar

Thanx Wolfgang
puzzle starts to fit itself ...
Jarda




Dne 30.9.2010 20:53, Wolfgang Schuster napsal(a):

Am 30.09.2010 um 20:40 schrieb Jaroslav Hajtmar:

   

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?
 

Yes.

   

2. If are ConTeXt macros defined in the module, are automatically in its 
namespace?
 

No, the namespace in a module is only for keys and key-value-lists. When you 
write a command with the same name as a core command the core definition is 
overwritten and lost.

   

3. Can both namespaces (module and Luacode) somehow connected?
 

You can try to use the same namespace in TeX and Lua but thats up to you.

   

4. What happens when I have two macros with the same name in two different 
modules?
 

The last definition is the current meaning of the command, e.g. in this example 
the command \befehl has the content “Befehl” because it’s the last defintion.

\def\befehl{command} % \befehl has not the content “command”

\def\befehl{Befehl} % \befehl has now the content “Befehl” and the content of 
the first definition is lost

   

5. Can I call the macros of the same names in different namespaces (diferent 
modules)?
 

When you call them inside of a environment it’s possible.

\def\startenvone{\bgroup\def\befehl{command}}
\def\stopenvone {\egroup}

\def\startenvtwo{\bgroup\def\befehl{befehl}}
\def\stopenvtwo {\egroup}

\starttext
\startenvone \befehl \stopenvone % \befehl == “command”
\startenvtwo \befehl \stopenvtwo % \befehl == “befehl”
\stoptext

   

6. Can I read about somewhere more?
 

- The programming pages on the wiki.
- A book about plain TeX {e.g. The TeXbook, TeX by Topic, TeX for the Impatient 
etc.)

   

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.
 

Give me some time to write a detailed description of the \definenamespace 
command.

Wolfgang


   


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


[NTG-context] Modules, namespaces, Luacode etc..

2010-09-30 Thread Jaroslav Hajtmar

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,
%Dtitle=\CONTEXT\ User Module,
%D subtitle=Module example,
%D   author=Author Name,
%D date=\currentdate,
%Dcopyright=Copyright,
%Demail=mailaddr...@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='', -- comment
gVar2='y', -- 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 
**

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


Re: [NTG-context] Modules, namespaces, Luacode etc..

2010-09-30 Thread Wolfgang Schuster

Am 30.09.2010 um 20:40 schrieb Jaroslav Hajtmar:

 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?

Yes.

 2. If are ConTeXt macros defined in the module, are automatically in its 
 namespace?

No, the namespace in a module is only for keys and key-value-lists. When you 
write a command with the same name as a core command the core definition is 
overwritten and lost.

 3. Can both namespaces (module and Luacode) somehow connected?

You can try to use the same namespace in TeX and Lua but thats up to you.

 4. What happens when I have two macros with the same name in two different 
 modules?

The last definition is the current meaning of the command, e.g. in this example 
the command \befehl has the content “Befehl” because it’s the last defintion.

\def\befehl{command} % \befehl has not the content “command”

\def\befehl{Befehl} % \befehl has now the content “Befehl” and the content of 
the first definition is lost

 5. Can I call the macros of the same names in different namespaces (diferent 
 modules)?

When you call them inside of a environment it’s possible.

\def\startenvone{\bgroup\def\befehl{command}}
\def\stopenvone {\egroup}

\def\startenvtwo{\bgroup\def\befehl{befehl}}
\def\stopenvtwo {\egroup}

\starttext
\startenvone \befehl \stopenvone % \befehl == “command”
\startenvtwo \befehl \stopenvtwo % \befehl == “befehl”
\stoptext

 6. Can I read about somewhere more?

- The programming pages on the wiki.
- A book about plain TeX {e.g. The TeXbook, TeX by Topic, TeX for the Impatient 
etc.)

 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.

Give me some time to write a detailed description of the \definenamespace 
command.

Wolfgang

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