Read Project File From Lua

Introduction

This example shows how to use the builtin Iguana file APIs to load files from a project for an Iguana translator instance. The technique is simply to understand the layout of the file system and use standard Lua file APIs to load the files in question.

If you have any questions please contact us at support@interfaceware.com.

Using the Code [top]

  • Import the Read Project File From Lua channel from the Builtin: Iguana Files repository
  • Experiment with the code to find out how it works
  • Adapt the code to your own requirements
  • Copy the loadFile() function into your script
    Note: You may want to put the loadFile() function in a module
  • Then just copy the code you need from main() into your script, and adapt it as needed

This is the github code for the main module:

How it works [top]

  • Find the root directory for the project (a subdirectory of the Iguana instance project root directory)
    • Use iguana.project.root() to find the root directory for the Iguana instance
    • Use iguana.project.guid()  to find the project guid
    • Append the guid to the root directory
  • Load a file from the project root directory
    • Use the loadFile() function to load the local.xml file
      Note: loadFile() uses builtin API functions to open, read and close a file
  • Load a file from the “other” directory (a subdirectory of the Iguana instance project root directory)
    • Append “other/example.xml” to the Iguana instance project root directory
    • Append the name of the file to load,  we appended “example.xml”
    • Use loadFile() to load the file

More information [top]