Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Config {
- var width: Int = 10
- private set
- init {
- val file = fopen("config.txt", "r")
- if (file != null) {
- try {
- val buffer = ByteArray(2 * 1024)
- while (true) {
- val nextLine = fgets(buffer.refTo(0), buffer.size, file)?.toKString()
- if (nextLine == null || nextLine.isEmpty()) break
- val records = nextLine.split('=')
- if (records.size != 2) continue
- val key = records[0].trim()
- val value = records[1].trim()
- when (key) {
- "width" -> width = value.toInt()
- }
- }
- }
- } finally {
- fclose(file)
- }
- }
- }
Add Comment
Please, Sign In to add comment