1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Implementation of `app::assets`
25 var ns_path
= ("assets"/path
).to_nsstring
26 var path_in_bundle
= asset_path
(ns_path
)
27 if path_in_bundle
.address_is_null
then
28 self.error
= new Error("TextAsset at '{path}' not found")
34 var text
= asset_content
(path_in_bundle
)
35 if text
.address_is_null
then
36 self.error
= new Error("Failed to read content of TextAsset at '{path}'")
45 private fun asset_path
(path
: NSString): NSString in "ObjC" `{
46 return [[NSBundle mainBundle] pathForResource:path ofType:nil];
49 private fun asset_url
(path
: NSString): NSObject in "ObjC" `{
50 return [[NSBundle mainBundle] URLForResource:path withExtension:nil];
53 private fun asset_content
(path
: NSString): NSString in "ObjC" `{
54 return [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];