VASmalltalk – Configuration of end user applications via Lua

With VA 8.5.1 the “official” way of offering configuration values to your application is by using the new configuration framework introduced with VA 8.5.

The idea here is to add a new section to your ini-file named with the name of your application.

An example of the configuration entries of a system can be the file name mapping I’ve seen in VA8.5.1

[PlatformLibrary Name Mappings]
SOCKET_PRIMS=essci40

and as a programmer you must implement the methods currentSettings, setCurrentSettings and validSettings on the class side of your application class.

With #currentSettings you may define current values and default values for a set of settings.

With #validSettings you define the set of entries you expect in this section and which data type each entry has.

With #setCurrentSettings you read the settings value and set them within your application. Have a closer look at EmLibraryInterface for their implementations and you may use it.

A totally different way of configuraion could be using the programming language Lua from Smalltalk.

Let us assume, that we have a text file named “abt.lua” with the following content:

PlatformLibraryNameMappings = { SocketPrims = "" };
if (isWindowsPlatform) then
  PlatformLibraryNameMappings.SocketPrims = "essci40"
else
  PlatformLibraryNameMappings.SocketPrims = "libessci40"
end 

and this file contains Lua code to be executed. Smalltalk will start a Lua interpreter, let Lua execute the source code and Smalltalk queries the result of the variables we are intested in.

This might be the Smalltalk code to execute the

"we have to retrieve the source code to execute"
codeString  = .... content from file abt.lua ....
"get a new interpreter"
anInterface := MSKLuaLibrary newLua.
"set variable isWindowsPlatform  we could ask Smalltalk for"
"the value. here we set it simply to true ..."
anInterface
  pushBoolean: true ;
  setGlobalNamed: 'isWindowsPlatform'.
"now execute the Lua code"
anInterface doString: codeString.
"and query the content of a variable"
anInterface 
  getValueFromTableNamed: 'PlatformLibraryNameMappings' 
  fieldName: 'SocketPrims'

and as a result you get “essci40”.

The main idea here is to set specific variables in the environment of Lua BEFORE executing the code and query the variable contents you need after the Lua program has been finished.

This is only one idea how to use Lua …

I’ve published an updated wrapper for Lua 5.2 at vastgoodies.com

This entry was posted in Smalltalk and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s