WChar

From OxeyeWiki

Revision as of 10:55, 7 March 2009 by Jeb (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Daisymoon GUI Lib

Contents

Introduction

All GUI elements in Daisymoon use a wide-character data type called "wchar_t". This type is 16 bits on Windows and 32 bits on Mac OS X (by default), and is used to enable Unicode characters that normal byte strings can't support. Unfortunately, Lua only supports 8-bit characters and recommends using UTF-8 for Unicode text. The work-around to this problem in Daisymoon is the WChar class.

WChar is a Lua Lunar implementation of a wide-byte string class. All GUI elements that needs to display text to the user will expect to receive strings using this class. For example, the setText method of the GUI elements is called by:

label:setText(WChar("Set the label text as a Unicode string"))

Usage

Constructors

The easiest way to use WChar is to create variables by calling the constructors. This is done by simply writing WChar(some value), where "some value" can be a string (normal 8-bit string), a number or another WChar. For example:

local labelText = WChar(healthValue)
label:setText(labelText)

or simply

label:setText(WChar(healthValue))

Modifying Strings

The WChar class has a number of methods you can use to modify its contents. These methods have been written so that they will be similar to those of the Lua string library.

Known Problems

The WChar class is used to write Unicode text, but the Lua parser itself doesn't support Unicode text, so it's not possible to create such strings in Lua scripts. For example, this code will not give the correct string value:

label:setText(WChar("In Swedish, we often use the å, ä and ö letters."))

In the future, this problem will be avoided by using language templates. In other words, text strings will be fetched from a property file instead of being written directly into the code. This will also allow the developer to support mutiple languages simply by including multiple property files.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox