💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
Haxe编译工具原来的目的是合成一些web技术到一种语言。支持Flash,JavaScript,和Neko,web开发者可以使用Haxe编译工具来使用这三种技术而不用学习新的语法。 而且,因为Haxe,Flash,JavaScript和Neko可以在Windows,Mac OS和Linux上进行开发,许多开发者就可以使用Haxe而不用改变他们喜好的操作系统。 随着时间的推移,更多技术的桥接也被开发出来。 基于Neko的一个重点,Haxe语言可以被进一步增强,而不用以任何方式修改编译工具。这通向其他令人兴奋的开发,比如SWHX(ScreenWeaver for Haxe)框架使用一个Flash GUI(Graphical User Interface)层来创建桌面应用,也可以使用我们自己的Neko Media Engine(NME),封装了 Simple DirectMedia Layer(SDL)框架和函数作为一个2D游戏API。 这里的重点是,Haxe编译工具并不是一项新技术,仅仅是一个程序,用来转换一种新的语言到一些旧的技术中。 使用Haxe的好处是极大的,但是可以概括为下面几点: * 使用现有的技术发挥它们最大的能力。 * 开发者之间的界限降低,提供更多的合作空间 * 开发团队之间的知识增加,因为他们编写代码延伸到他们同行的技术 * 项目迅速建立,并且有更少的错误和平台障碍 * 项目更容易维护,因为所有团队成员都能理解语言语法而不用理解部署的技术 * Haxe类为一种技术开发,然后可以很容易的编译到另一个技术. ## 编译到Flash Flash是一个不错的平台。事实的确如此,作为最流行的web多媒体平台,没有其它工具可以撼动它的位置,很难为其找到一个竞争者(译者注:如今HTML5的发展势头已经超过Flash)。以其在许多机器和操作系统下的能力,可以肯定的说Flash在未来一段时间内仍将如此。尽管传言称微软的新的开发技术会威胁到它。 The Flash IDE, synonymous to developers who create Flash movies, contains its own version of a Flash file compiler, as does the new Flex Builder application from Adobe. These tools are probably the forerunners in commercial Flash development, but are not needed to create complete Flash applications. Since the introduction of ActionScript 2.0 — the scripting language behind Flash movies — developers have had the ability to write applications using pure code. Unfortunately, though, the Flash IDE is not the most ideal environment for building Flash files in this way, as it is aimed primarily at designers. Flex provides a better solution, but still has drawbacks. If you contemplate both Flash and Flex and their relative language syntax — ActionScript 1 and 2 for the Flash IDE and MXML & ActionScript 3 for Flex Builder — you will see two very different programs and languages compile to the same platform. Granted, the Flash IDE compiles to Flash versions 9 and below (ActionScript 1, 2, and 3) whereas the Flex Builder IDE compiles to Flash version 9 alone (ActionScript 3), but they inherently perform the same feat. haXe is able to perform the same routine of compiling from a source language syntax to the Flash byte code specification, much like the Flash IDE and Flex Builder, except that haXe is able to compile a single language to both the complete Flash 6 to 8 specifications and the Flash 9 specification. That ’ s pretty impressive in our book (pun intended). haXe makes all of this possible by providing a language that is loosely coupled to the output, which is why it is able to support so many platforms. All haXe needs to understand is which equivalent structures for each platform map to the haXe structures and how it should be serialized in the output file. The Flash SWF file, which is one such output, is a document containing a series of codes in the form of bytes. Each byte represents media, functions, variables, or properties that make up the content of the movie and describe to the Flash virtual machine (or player) the exact content and functionality of the movie. When compiling to Flash, haXe produces the same SWF output and provides all of the same features as the official Flash compilers produced by Adobe, though of course, certain functions within the haXe library may not be supported depending on which version of Flash you are compiling against. You can handle this using compiler directives that allow different portions of code to be compiled depending on the target technology。 For those of you who are used to the MTASC compiler by Nicolas Cannasse for ActionScript versions 8 and below, haXe steps in as the successor, reducing further development of the MTASC compiler to bug fixes only. When MTASC (Motion - Twin ActionScript Compiler) was released several years ago, many developers saw, for the first time, their first break into the world of Flash. Previously, many developers would complain that the Flash IDE was far too geared toward the designer and left little leverage for the developer. MTASC changed all of that by offering an all - code entry point using tools they were already familiar with. haXe follows this developer - friendly route, though with its powerful yet friendly syntax, it also offers designers the chance to tinker in the world of the developer. ## 编译到JavaScript JavaScript has been around for some time, but for client - side browser scripting, there is no competition. While Internet Explorer provides access to the Visual Basic scripting interpreter, JavaScript is still the only scripting language supported by the majority of browsers, and so is the only choice for thousands of developers worldwide. Each of the well - known browsers supports quite a variation of the JavaScript API. The most noted differences are those between the Internet Explorer JavaScript engine and the Mozilla JavaScript engine, which have been the source of much pulling of hair for web developers everywhere for a number of years. When you build applications that rely heavily on client - side scripting over various browser types, it is a necessity to include numerous hacks and tricks to avoid facilitating functionality that performs well on some browsers, yet poor on others. When compiling to JavaScript with the haXe compiler, haXe provides a set of functions that form a small framework for maintaining suitable cross - browser JavaScript functionality. ## 编译为Neko Haxe编译到Neko字节码格式,这和处理Flash字节码的方式类似。编译后的文件被Neko虚拟机使用,同样和Flash虚拟机的形式类似,虽然一些用户的支持必须使用一些第三方库。 Usually, one would write for the Neko virtual machine for the purpose of creating server - side web logic using the mod_neko module or to create a desktop application for use in a command console or batch file. Using third - party modules, it is also possible to create desktop applications and full network ready server frameworks of any scale. Although not much has been mentioned yet about the Neko language, compiler, and virtual machine, they do form a fairly substantial part of this book. The Neko framework is discussed in detail in Chapter 9 , “ Building Websites with haXe. ”