Notes when using wax

Source: Internet
Author: User

Note when using wax (https://github.com/probablycorey/wax/wiki/Overview ).

Although wax can coordinate OC and Lua, wax has some functional limitations and corresponding solutions. Lower
This section describes some notes:

1. when instantiating an OC object, you do not need to call alloc because wax has helped us deal with it. At the same time, there is no need to adjust
With retain or release, it is said that Lua has implemented a garbage collection mechanism similar to Java.
Literature Review or test-by-test.

For example, local view = uiview: initwithframe (cgrect (0, 0,100,100 ))

2. To create an OC class in Lua, you only need to call the waxclass {class_name, parent_class} function.
When creating a file, in principle, a file can only create one class, because wax treats all functions in the file
Method of this class.

For example: waxclass {"myclass", nsobject}

Equivalent to waxclass ({"myclass", nsobject })

Of course, to add the Protocol (Protocols), you can:

Waxclass {"myclass", nsobject, protocols = {"uitableviewdelegate", "UI
Tableviewdatasource "}}

Description: The first parameter indicates the class name to be created, the second parameter indicates the parent class to be inherited, and the third parameter table.
List of protocols to be implemented.

3. The OC method called in Lua is to use a colon instead of vertices, square brackets, or other methods.

For example, uiapplication: sharedapplication ()

Note: nodes in Lua can dynamically create member variables (while in oCCode),
These members are valid in the object lifecycle.

4. In Lua, there is no such keyword as his or self, but wax provides us with a solution, that is
The first parameter (required) in the method is self, that is, all functions in the class defined in Lua, the first
The parameter must be self, and from the second parameter is the parameter we want to pass.

For example: waxclass {"myclass", nsobject}

Function storewords (self, words)

Self. Words = words

Self. Super: words (Self)

End

Note: If you want to call the method of the parent class, wax has prepared the super attribute for us, as shown in the preceding example.

5. In the OC method, multiple parameters are often required. In wax, underscores (_) are used to replace the colon in OC.

For example, in OC: [uialertview initwithtitle: @ "title" message: @ "message" Deleg
Ate: Nil];

In wax: uialertview: initwithtitle_message_delegate ("title", "mescript
E ", nil)

6. If a variable in a class in OC declares properties, it cannot be directly assigned or obtained in wax.
To call the getters/settes method.

For example, in OC: someview. Frame

In wax: someview: frame ()

Someview: setframe (someframe)

7. If we do not want the OC object to be automatically converted, we can use the toobjc method.

For example, local string = "a string"

String: capitalizedstring ()

At this time, the string is luastring, so an error is returned when you call the capitalizedstring () method.
.

If you do this as follows, the luastring will be converted to nsstring, then nsstrin can be used.
The method in G is:

Toobjc (string): capitalizedstring ()

8. The Enumeration type is hardcoded in app_root/wax/stdlib/enums. Lua. That is to say, we want
To add an enumeration type, you must register the enumeration type in enums. Lua. For the specific registration method, see enums. Lua. However
, The newly added enumeration here needs to be reencoded using the compile-stdlib.sh to take effect. Of course, you can also
The defined Lua file declares that you only need to introduce the Lua file in the appropriate location.

9. In oC, selector is often passed. In wax, the string in selector is treated as a string.

For example, in OC: [self scheduleonce: @ selector (maketransition :) delay: 1];

In wax: Self: scheduleonce_delay ("maketransition", 1)

10. struct in OC are not supported in wax. The struct is also hard-coded in wax, and in app_root
/Wax-scripts/structs. Lua. After reading this file, you should be able to know how to make the structure declaration.
. Refer. 11. To add a comment, the single line Comment Method in Lua is in the two dashes ("--")
The multiline comment method starts with "-- [" and ends.
--
※Source: · Yu Xin bbs.eistar.net · [from: 222.20.59.106]

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.