lib/cocoa: intro the cocoa library to wrap cocoa, foundation and app_kit
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 2 Dec 2014 22:47:56 +0000 (17:47 -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/app_kit.nit [new file with mode: 0644]
lib/cocoa/cocoa.nit [new file with mode: 0644]
lib/cocoa/foundation.nit [new file with mode: 0644]

diff --git a/lib/cocoa/app_kit.nit b/lib/cocoa/app_kit.nit
new file mode 100644 (file)
index 0000000..91bc87c
--- /dev/null
@@ -0,0 +1,38 @@
+# 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.
+
+# The Application Kit provides services to create GUI
+module app_kit is c_linker_option "-framework AppKit"
+
+import foundation
+
+in "ObjC Header" `{
+       #import <AppKit/AppKit.h>
+`}
+
+# A simple message box
+extern class NSAlert in "ObjC" `{ NSAlert * `}
+       super NSObject
+
+       # Allocate and instanciate a new `NSAlert`
+       new in "ObjC" `{ return [[NSAlert alloc] init]; `}
+
+       # Set the content of this message box
+       fun message_text=(text: NSString) in "ObjC" `{ [recv setMessageText:text]; `}
+
+       # Show this message box
+       fun run_modal in "ObjC" `{ [recv runModal]; `}
+end
diff --git a/lib/cocoa/cocoa.nit b/lib/cocoa/cocoa.nit
new file mode 100644 (file)
index 0000000..99c6b12
--- /dev/null
@@ -0,0 +1,26 @@
+# 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.
+
+# The Cocoa API is the development layer of OS X
+#
+# This module is only compatible with OS X.
+#
+# This wrapper of the Cocoa API regroups the Foundation Kit and the
+# Application Kit.
+module cocoa is c_linker_option "-framework Cocoa"
+
+import foundation
+import app_kit
diff --git a/lib/cocoa/foundation.nit b/lib/cocoa/foundation.nit
new file mode 100644 (file)
index 0000000..ab027fd
--- /dev/null
@@ -0,0 +1,47 @@
+# 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.
+
+# The Foundation Kit provides basic Objective-C classes and structures
+module foundation is c_linker_option "-framework Foundation"
+
+in "ObjC Header" `{
+       #import <Foundation/Foundation.h>
+`}
+
+# Base of the Foundation framework class hierarchy
+extern class NSObject in "ObjC" `{ NSObject * `}
+end
+
+# String of the Foundation Kit
+#
+# Created using `Text::to_nsstring`.
+extern class NSString in "ObjC" `{ NSString * `}
+       super NSObject
+end
+
+redef class NativeString
+       # Get a `NSString` from `self` with the specified `length`
+       fun to_nsstring(length: Int): NSString in "ObjC" `{
+               return [[NSString alloc] initWithBytes:recv
+                       length:length
+                       encoding:NSASCIIStringEncoding];
+       `}
+end
+
+redef class Text
+       # Get a `NSString` from `self`
+       fun to_nsstring: NSString do return to_cstring.to_nsstring(length)
+end