* Luacode: Data File to Table
@ 2019-10-24 12:44 Rudolf Bahr
2019-10-24 15:11 ` Taco Hoekwater
0 siblings, 1 reply; 3+ messages in thread
From: Rudolf Bahr @ 2019-10-24 12:44 UTC (permalink / raw)
To: ntg-context
[-- Attachment #1: Type: text/plain, Size: 2524 bytes --]
Hi All!
LuaMetaTeX, Version 2.00.0
ConTeXt ver: 2019.10.10 18:15 MKIV beta fmt: 2019.10.19 int: english/english
I'd like to transfer the entries in a data file to a Lua table according to [1].
Here a MWE of my data file, appended as file Rosi.lua:
--------------------------
Rosi{
smrk = "00-003",
picture_file = "/home/sam/pictures/",
picture_name = "00-003---1981---Provence.png",
width_px = "394",
height_px = "481",
}
Rosi{
smrk = "00-006",
picture_file = "/home/sam/pictures/",
picture_name = "00-006---1986---Eire.png",
width_px = "392",
height_px = "479",
}
And here is my MWE in Luacode:
------------------------------
\startluacode
userdata = userdata or {}
u = userdata
function u.Hugo ( )
local S = {}
function Rosi (b)
S [ b.smrk ] = {
[ "smrk" ] = b.smrk,
[ "picture_file" ] = b.picture_file,
[ "picture_name" ] = b.picture_name,
[ "width_px" ] = b.width_px,
[ "height_px" ] = b.height_px,
}
context ( 'function Rosi(): b.smrk = ', b.smrk )
context.par()
end
require ("Rosi")
end
\stopluacode
\starttext
\currenttime
\def\Heidi%
{\ctxlua{u.Hugo()}}
\Heidi
\stoptext
The entries in Rosi.lua aren't recognized in Luacode! The output pdf is appended
as well.
Now the essential part of the MWE above in pure Lua. Here it works! Strange.
-----------
userdata = userdata or {}
u = userdata
function u.Hugo ( )
S = {}
function Rosi (b)
S [ b.smrk ] = {
[ "smrk" ] = b.smrk,
[ "picture_file" ] = b.picture_file,
[ "picture_name" ] = b.picture_name,
[ "width_px" ] = b.width_px,
[ "height_px" ] = b.height_px,
}
print ( "b.smrk = " .. b.smrk )
end
require ("Rosi")
print ( S["00-003"]["width_px"], S["00-003"]["height_px"] )
print ( S["00-006"]["width_px"], S["00-006"]["height_px"] )
end
u.Hugo ()
Please, what could be done?
Best wishes,
Rudolf
[1] Roberto Ierusalimschy: Programming in Lua, Fourth edition, chapter 15.1 Data Files
[-- Attachment #2: Rosi.lua --]
[-- Type: text/plain, Size: 382 bytes --]
Rosi{
smrk = "00-003",
picture_file = "/home/sam/pictures/",
picture_name = "00-003---1981---Provence.png",
width_px = "394",
height_px = "481",
}
Rosi{
smrk = "00-006",
picture_file = "/home/sam/pictures/",
picture_name = "00-006---1986---Eire.png",
width_px = "392",
height_px = "479",
}
[-- Attachment #3: Hugo-test.pdf --]
[-- Type: application/pdf, Size: 5893 bytes --]
[-- Attachment #4: Type: text/plain, Size: 493 bytes --]
___________________________________________________________________________________
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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Luacode: Data File to Table
2019-10-24 12:44 Luacode: Data File to Table Rudolf Bahr
@ 2019-10-24 15:11 ` Taco Hoekwater
2019-10-24 15:44 ` Rudolf Bahr
0 siblings, 1 reply; 3+ messages in thread
From: Taco Hoekwater @ 2019-10-24 15:11 UTC (permalink / raw)
To: mailing list for ConTeXt users
Here is the problem:
> context ( 'function Rosi(): b.smrk = ', b.smrk )
That should be:
context ( 'function Rosi(): b.smrk = ' .. b.smrk )
since the context() function does not support variable argument lists (not not like print())
Best wishes,
Taco
___________________________________________________________________________________
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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Luacode: Data File to Table
2019-10-24 15:11 ` Taco Hoekwater
@ 2019-10-24 15:44 ` Rudolf Bahr
0 siblings, 0 replies; 3+ messages in thread
From: Rudolf Bahr @ 2019-10-24 15:44 UTC (permalink / raw)
To: mailing list for ConTeXt users
On Thu, Oct 24, 2019 at 05:11:50PM +0200, Taco Hoekwater wrote:
> Here is the problem:
>
> > context ( 'function Rosi(): b.smrk = ', b.smrk )
>
>
> That should be:
>
> context ( 'function Rosi(): b.smrk = ' .. b.smrk )
>
> since the context() function does not support variable argument lists (not not like print())
>
> Best wishes,
> Taco
Yes, that's ok now! It works. Thank you, Taco!
Best wishes,
Rudolf
___________________________________________________________________________________
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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-10-24 15:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-24 12:44 Luacode: Data File to Table Rudolf Bahr
2019-10-24 15:11 ` Taco Hoekwater
2019-10-24 15:44 ` Rudolf Bahr
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).