ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Rudolf Bahr <quasi@quasi.de>
To: ntg-context@ntg.nl
Subject: Luacode: Data File to Table
Date: Thu, 24 Oct 2019 14:44:58 +0200	[thread overview]
Message-ID: <20191024124458.GA27123@nan> (raw)

[-- 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
___________________________________________________________________________________

             reply	other threads:[~2019-10-24 12:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-24 12:44 Rudolf Bahr [this message]
2019-10-24 15:11 ` Taco Hoekwater
2019-10-24 15:44   ` Rudolf Bahr

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191024124458.GA27123@nan \
    --to=quasi@quasi.de \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).