lib/cocoa: intro an example with extern Objective-C classes
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 9 Dec 2014 22:30:26 +0000 (17:30 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Wed, 10 Dec 2014 12:59:16 +0000 (07:59 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/cocoa/examples/cocoa_extern_types.nit [new file with mode: 0644]
tests/sav/cocoa_extern_types.res [new file with mode: 0644]

diff --git a/lib/cocoa/examples/cocoa_extern_types.nit b/lib/cocoa/examples/cocoa_extern_types.nit
new file mode 100644 (file)
index 0000000..775e6e4
--- /dev/null
@@ -0,0 +1,43 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Test extern classes from the Cocoa framework and extern factories
+module cocoa_extern_types
+
+import cocoa
+
+in "ObjC Header" `{
+       // for `NSString::hello`
+       #import <Foundation/Foundation.h>
+`}
+
+redef extern class NSString
+
+       # Additionnal factory
+       new hello in "ObjC" `{ return @"Factory Hello"; `}
+end
+
+# Print a custom string to the log
+fun nslog(text: NSString) in "ObjC" `{
+       NSLog(text);
+`}
+
+nslog "Hello using to_nsstring".to_nsstring
+nslog new NSString.hello
+
+var msg_box = new NSAlert
+msg_box.message_text = "From Nit".to_nsstring
+if "NIT_TESTING".environ != "true" then msg_box.run_modal
diff --git a/tests/sav/cocoa_extern_types.res b/tests/sav/cocoa_extern_types.res
new file mode 100644 (file)
index 0000000..4ad3dc3
--- /dev/null
@@ -0,0 +1 @@
+UNDEFINED