1
iachieveditからの指示でmccunewareのncursesパッケージを使用すると、エラーなしで次のコードを実行できません。小さなncursesアプリケーションを作成しようとしましたが、エラー:式が最上位レベルで許可されていません
import Foundation
import CNCURSES
import Glibc
enum Signal:Int32 {
case INT = 2
case WINCH = 28
}
typealias SignalHandler = __sighandler_t
func trap(signum:Signal, action:SignalHandler) {
signal(signum.rawValue, action)
}
trap(.INT) { signal in
endwin()
exit(0)
}
initscr()
noecho() // Turn on noecho, though it doesn't matter in this example
curs_set(0) // 0 is invisible, 1 is visible, 2 is very visible
move(0, 0)
addstr("UL")
refresh() // This is required to update the screen
move(23,78)
addstr("LR")
refresh()
select(0, nil, nil, nil, nil) // Wait
エラーは次のとおりです。
Compile Swift Module 'ncurses' (1 sources)
/home/luis/Dropbox/Documentos/Coding/Swift/ncurses/Sources/ncurses.swift:17:1: error: expressions are not allowed at the top level
initscr()
^
ディレクトリ構造は次のとおりです。
のncurses/Package.swift
のncurses /ソース/ ncurses.swift
そして、前述のCNCURSESはPackage.swift内で呼び出されます:
// swift-tools-version:3.1
import PackageDescription
let package = Package(
name: "ncurses",
dependencies: [
.Package(url: "https://github.com/mccuneware/CNCURSES", majorVersion:1),
]
)
指示が古くなっているようですが、エラーを回避するにはどうすればよいですか?
main.swiftファイルにありますが、質問をディレクトリ構造で更新します。 –
ああ、ok ...それを試してみる...ありがとう –
はい、ポイントは、ルートレベルの指示*を含むファイルは、何もmain.swiftという名前でなければならないということです。他のファイルは存在する可能性がありますが、トップレベルの指示はできません。 :) – Moritz