SLua: Read Notecard

<code lua load-notecard.lua>

– load-notecard.lua - Read a notecard into LSD local CONFIG_NOTECARD = “notecard” local card_query local line

function dataserver(queryid:uuid, data:string)

  if queryid == card_query then
      if data ~= EOF then
          -- Skip comments
          local ix = ll.SubStringIndex(data, "#")
          if ix ~= -1 then
              if ix == 0 then
                  data = ""
              else
                  data = ll.GetSubString(data, 0, ix-1)
              end
          end
  1. - If the data looks like a key…

if (data ~= “”) and (data ~= “#”) and (data ~= NULL_KEY) then

  1. - Process line

ll.OwnerSay(string.format(“ %s\n”, data))

          end
          -- Read next line
          line = line + 1
          card_query = ll.GetNotecardLine(CONFIG_NOTECARD, line)
      else
          -- Done
          ll.OwnerSay("Configuration complete")
      end
  end

end

local function main()

  ll.SetText(ll.GetObjectDesc(), vector.create(1, 1, 1), 1.0);
  if ll.GetInventoryType(CONFIG_NOTECARD) == INVENTORY_NOTECARD then
      -- Read the notecard
      ll.OwnerSay(string.format("Reading %s:\n", CONFIG_NOTECARD))
      line = 0
      card_query = ll.GetNotecardLine(CONFIG_NOTECARD, line)
  else
      ll.OwnerSay(string.format("notecard %s not found\n", CONFIG_NOTECARD))
  end

end

main()