Wtl Application Wizard (LUA version) source code Introduction

Source: Internet
Author: User
Original visualfc
The wtl Application Wizard (LUA) is compiled using iuplua. This article briefly describes its source code and analyzes the multilingual interface processing mechanism of the wizard.
The source code of the wtl Application Wizard can be downloaded from http://code.google.com/p/visualfc/downloads/list. The following is a brief description.

I. Development Environment:
The wizard development environment is Lua for windows, the Project address is: http://luaforwindows.luaforge.net/

Wiz_main.wlua is the main wizard file, written in plain text format.
Wiz_chs.wlua is a Chinese wizard. After the Chinese interface is initialized, wiz_main.wlua is called.
The Resource Directory is a Chinese resource file and image used by the wizard.
The template directory is the Application Wizard template directory. You can obtain and add some functions from the wtl80 release package.

Ii. Wizard control:
The current version of iuplua (2.7) does not provide a wizard control, so I used iuplua to write a wizard control. The source code is located in the iup/iupwizard. Lua file.

Iii. iup ID extension:
This has been introduced in previous articles. Here is only an example of iup. button {Title = "OK", id = "btn_id"}. You can directly reference btn_id to indicate this button. The source code is in iup/iupid. in Lua.

Iv. vswizard. dll file
It mainly provides the template file analysis function under the template directory and some auxiliary functions for Lua.
This is transplanted from the wtl Wizard of VFC. The source code is located in the source/iup_vswizard directory.
The luabind directory is a simple binding from C ++ to Lua.

5. absolute path
I found it difficult to obtain the absolute path of the Lua file in Lua. Finally, I used to export get_module_path in vswizard. dll.
The function method is used by the Lua module. If anyone has a simpler method, I hope to improve it.

6. multilingual interface processing:
Iup currently does not support Unicode, But it supports code pages. The multi-language processing in this wizard uses the Lua table method for processing. In the Lua source file, the string must be displayed, and the "sample string" is replaced by the UI ("sample string ".

By using the multi-language generation tool resource/build_lang.lua, you can directly extract the UI ("...") from the Lua source file and generate
Lang_chs.lua for translation. After modifying the UI string in the Wizard, run build_lang.lua again to extract the UI ("...") string and
It does not affect the translated strings.
I intercepted some source code of resource/lang_chs.lua, which is automatically generated by build_lang.lua.

Local lang = {}
Lang ["project name"] = "project name"
Lang ["location"] = "local directory"

-- UI ("test Str ")
Function UI (STR)
If Lang [STR] ~ = Nil and Lang [STR] ~ = "" Then
Return Lang [STR]
Else
Return Str
End
End

The source code of the wiz_main.wlua file on the Chinese interface is as follows:

Require "vswizard"

Local app_path = vswizard. get_module_path ()
Local_lang = string. Upper (vswizard. get_local_lang ())

If local_lang = "CHS" then
Dofile (app_path .. "// resource // lang_chs.lua ")
End

Dofile (app_path .. "// wiz_main.wlua ")

If the current language is Chinese, load the lang_chs.lua file and obtain the UI function. In wiz_main.wlua, check whether the UI function has been obtained. If not, use the source string output. Local UI = ui or function (STR) return STR end

Finally, let's take a look at the source code of build_lang.lua, from which we can find that it is very easy to use Lua for such tools.

Function make_file (name, out_name)
File = Io. Open (name, "R ")
Assert (file, "error to Load file" .. name)

S = file: Read ("* All ")
Words = {}
Saves = {}
For W in string. gmatch (S, "UI % s-% (% S-(/".-/") % s-%)") Do
If words [w] = nil then
Saves [# saves + 1] = W
Words [w] = [[""]
End
End

File: Close ()

File = Io. Open (out_name, "R ")
Old = ""
If file then
Old = file: Read ("* All ")
End
For W, W1 in string. gmatch (old, "Lang % [(/". -/") %] % s-= % S -(/". -/")") Do
If W1 ~ = "" Then
Words [w] = W1
End
End

File = Io. Open (out_name, "W ")
Assert (file, "error to Write File" .. out_name)

File: Write ("-- Lang file for"... name... "/n ")
File: Write ("Local lang = {}/N ")
For K, V in ipairs (saves) Do
File: Write (string. Format ("Lang [% s] = % s/n", V, words [v])
End
File: Write (
[[

-- UI ("test Str ")
Function UI (STR)
If Lang [STR] ~ = Nil and Lang [STR] ~ = "" Then
Return Lang [STR]
Else
Return Str
End
End

])
End

Make_file (".. // wiz_main.wlua", "lang_chs.lua ")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.