Devgineers

 

Creating and Working with Addon Libraries

One of the neat features of Lua that we’ve leveraged in several of the Atlas addons is the ability to create a library system in which you can take code that is used frequently, compartmentalize it by placing it into a separate file and then utilize that code in multiple different places.

In a number of the Atlas addons, we were faced with the problem of generating URL fragments based on data available in request records. When we first approached this, we did so somewhat naively and just appended the necessary bits of data to the URL string. This of course caused problems when those pieces of data contained characters that aren’t valid as part of a URL and need to be encoded. To fix this, we created a method that takes a string and returns a URL encoded version. Since we needed that same functionality in several scripts, we extracted the method out into a separate file (which now also contains a couple other functions) which we called AtlasHelpers.lua. Once we did that, we were able to place that file in a central location in our addons folder (specifically, we placed it in the Atlas folder) and simply include it in any addons that need it. This simplified the addons that needed that functionality, since they didn’t all have to have that method in them. It also simplified the process of fine tuning and enhancing that method since we now only have to change it in one place.

So how does this work? Well, fortunately we didn’t actually have to do a whole lot to make this work, since Lua already supports a method for including files. The Lua language itself supports a command called “require”, which takes a single string argument; the string is formatted sort of like a C# or Java namespace and is used to locate and load a code library for use in the script that called require. For exact details on how the Lua system handles the require command, you can see the documentation here, but essentially the string you pass in is treated as a dot delimited file path to the file you are trying to include. Lua plugs the string into a search pattern defined by a global path variable, finds the file and loads it. All we’ve done is to change the loading process for addons so that before loading an addon’s script files, the path variable gets set to something more useful. Specifically, we set the path to “{CurrentAddonDirectory}\\?.lua;{HostAppPath}\\Addons\\?.lua” where HostAppPath is the folder the host application’s executable file resides in, and CurrentAddonDirectory is the base directory for the currently executing addon. What this means for addon developers is that we can now create Lua files inside of our addon folders and reference them just by using something to the effect of:

require "AtlasHelpers"

In addition, we can take those helper files, put all the ones you tend to use repeatedly into a single file in your Addons directory and reference those files with a call as simple as:

require "Atlas.AtlasHelpers"

Now some people may be thinking “Well Travis, that’s awesome and all, but how do I distribute my libraries from a network share if I don’t put them in an addon that will get pulled down automatically?”

Well, we thought of that. What we chose to do was make it so that you can add a config.xml file to your libraries that identifies them as such. The addon system will then see the config file, recognize that it is something it needs to deal with and handle it appropriately. Specifically, it will do all the same version checking that it does for actual addons, and if the network share has a new version, it will be pulled down just like any addon would. There are, however, a couple minor catches. First, while the config files are setup very similarly to the addon config files (in fact, they use the exact same schema definition and get loaded into the exact same class in the scripting system) there is one tag that is required for libraries, as well as some tags that are required for addons but are completely unnecessary for libraries. Below you can see an example of a library’s config.xml file.


	Atlas Library
	Atlas Systems, Inc.
	1.0
	false
	Library

	Contains helper methods for use with user addons.

The first thing you will probably notice is that there are several missing sections. The Forms, Settings, and Files sections are all optional sections in the xml schema and can be safely excluded when dealing with libraries. In addition, you may notice that there is a new tag named Type. The Type element can have one of two values: Library or Addon. These are pretty self explanatory. The only note I will make about this tag is that the tag itself is optional, and it defaults to Addon. This means the tag is unnecessary for addons, but required if you want to identify a library as a library.

So to recap: We can now use libraries in addons by creating the library code files in a separate folder in the addons directory, creating a config file for the library making sure to set the value of the Type element to “Library”, and then using the require statement to include the file in the addons that need it.

Distributing addons with pre-defined layouts

With the ability to add multiple controls to an addon form, addon authors now face the challenge of designing the user interface and ensuring that the UI design is the same when another user installs their addon. While UI design is never easy, the Customize Layout feature that exists takes some of the pain away. All addon forms are capable of layout customizations. A simple right click on the addon form will allow a user to customize the layout. After addon developers create the components they’ll need in their addon script, they can save a layout to an xml file in their local addon path which can be distributed with their addon. (more…)

Working with the Browser Control: Creation and Navigation

Hey everybody!

In this post I want to go over some of the basic information on the Browser control that currently exists in the addon system. First though, it is interesting to note that originally the only control available to the addon system was the browser control. In the original system, any time you created a browser interface it automatically attached itself to a form and added that form to the form the addon was running on. Now, however, we’ve expanded the support for user interface building to include a number of other controls such as text editors, grids, drop down menus, and more. I mention this because it is important to note, for those that dealt with the original browser interface, that all of the new form functionality is completely backwards compatible. Any browser interfaces that were created in the old system can still be used as is in the new system. However, because we now consider them obsolete, I won’t be talking about them, and instead I will be focusing on the new, improved version: the Browser control. (more…)

Working with the Browser Control: Page Handlers

Welcome to part two of my five part series on working with the browser control. In this article, I want to talk about page handlers. I’m going to go briefly over what they are and what types are available, and then I will show and discuss an example of how to use them effectively. Then I will finish up by going over a couple special cases like handling AJAX page changes.
(more…)

Data Access via Addons

While I was at the IDS conference last year, I had the pleasure of making a presentation on the current version of the Addons system. The session went well, but I was a little surprised by how much interest people showed in a particular topic – data access. A number of questions popped up and several tweets were sent about the data access capabilities we put into the latest release. Since there seems to be so much interest in the topic, I figured it might be an interesting topic to discuss here – and now here we are.

I would like to start by pointing out that the data access components are only included in the 8.0.8.0 release – they were not part of the original addons functionality; and with that important aside out of the way, let’s dig into the data access components and see what data access options are available and then look at how we can use them.

First let’s look at the two data access options that are currently available. (more…)

Introducing the Devgineer Blog

Welcome to the inaugural post of the Atlas Devgineers blog. You may be asking, who are the Atlas Devgineers? The Devgineers is the new name for the software development team at Atlas Systems, Inc. The team consists of four members: Matt Calsada, Dustin Stokes, Travis Stokes, and Jacob Baughman. Together, the four of us handle development and maintenance of all of Atlas’ software products. You may have seen a few of us at various conferences, along with other representatives from Atlas, which we frequently attend in order to help provide information about our products.
(more…)

x
Loading...