[NTG-context] Luacode: Data File to Table

Rudolf Bahr quasi at quasi.de
Thu Oct 24 14:44:58 CEST 2019


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
-------------- next part --------------
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",
}

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Hugo-test.pdf
Type: application/pdf
Size: 5893 bytes
Desc: not available
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20191024/f772c021/attachment.pdf>


More information about the ntg-context mailing list