-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
44 changed files
with
738 additions
and
503 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.kingmang.lazurite.core | ||
|
||
import com.kingmang.lazurite.exceptions.LzrException | ||
import com.kingmang.lazurite.runtime.ClassInstanceValue | ||
import com.kingmang.lazurite.runtime.values.* | ||
|
||
fun LzrValue.asLzrNumber(lazyMessage: (() -> String)? = null): LzrNumber { | ||
return asLzrType(Types.NUMBER, lazyMessage) | ||
} | ||
|
||
fun LzrValue.asLzrString(lazyMessage: (() -> String)? = null): LzrString { | ||
return asLzrType(Types.STRING, lazyMessage) | ||
} | ||
|
||
fun LzrValue.asLzrArray(lazyMessage: (() -> String)? = null): LzrArray { | ||
return asLzrType(Types.ARRAY, lazyMessage) | ||
} | ||
|
||
fun LzrValue.asLzrMap(lazyMessage: (() -> String)? = null): LzrMap { | ||
return asLzrType(Types.MAP, lazyMessage) | ||
} | ||
|
||
fun LzrValue.asLzrFunction(lazyMessage: (() -> String)? = null): LzrFunction { | ||
return asLzrType(Types.FUNCTION, lazyMessage) | ||
} | ||
|
||
fun LzrValue.asLzrClass(lazyMessage: (() -> String)? = null): ClassInstanceValue { | ||
return asLzrType(Types.CLASS, lazyMessage) | ||
} | ||
|
||
inline fun <reified T : Any> LzrValue.asLzrType(targetType: Int, noinline lazyMessage: (() -> String)?): T { | ||
if (isLzrType(targetType)) return this as T | ||
if (lazyMessage == null) throwTypeCastException(type(), targetType) | ||
throwTypeException(lazyMessage.invoke()) | ||
} | ||
|
||
fun throwTypeCastException(origin: Int, target: Int): Nothing { | ||
throwTypeCastException(Types.typeToString(origin), Types.typeToString(target)) | ||
} | ||
|
||
fun throwTypeCastException(origin: String, target: String): Nothing { | ||
throwTypeException("Cannot cast $origin to $target") | ||
} | ||
|
||
fun throwTypeException(message: String): Nothing { | ||
throw LzrException("TypeException", message) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.kingmang.lazurite.core | ||
|
||
import com.kingmang.lazurite.runtime.values.LzrValue | ||
|
||
|
||
fun LzrValue.isLzrNumber(): Boolean { | ||
return isLzrType(Types.NUMBER) | ||
} | ||
|
||
fun LzrValue.isLzrString(): Boolean { | ||
return isLzrType(Types.STRING) | ||
} | ||
|
||
fun LzrValue.isLzrArray(): Boolean { | ||
return isLzrType(Types.ARRAY) | ||
} | ||
|
||
fun LzrValue.isLzrMap(): Boolean { | ||
return isLzrType(Types.MAP) | ||
} | ||
|
||
fun LzrValue.isLzrFunction(): Boolean { | ||
return isLzrType(Types.FUNCTION) | ||
} | ||
|
||
fun LzrValue.isLzrClass(): Boolean { | ||
return isLzrType(Types.CLASS) | ||
} | ||
|
||
inline fun LzrValue.isLzrType(targetType: Int): Boolean = type() == targetType |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/kingmang/lazurite/core/TypesSafeCastExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.kingmang.lazurite.core | ||
|
||
import com.kingmang.lazurite.runtime.ClassInstanceValue | ||
import com.kingmang.lazurite.runtime.values.* | ||
|
||
fun LzrValue.asLzrNumberOrNull(): LzrNumber? { | ||
return asLzrTypeOrNull(Types.NUMBER) | ||
} | ||
|
||
fun LzrValue.asLzrStringOrNull(): LzrString? { | ||
return asLzrTypeOrNull(Types.STRING) | ||
} | ||
|
||
fun LzrValue.asLzrArrayOrNull(): LzrArray? { | ||
return asLzrTypeOrNull(Types.ARRAY) | ||
} | ||
|
||
fun LzrValue.asLzrMapOrNull(): LzrMap? { | ||
return asLzrTypeOrNull(Types.MAP) | ||
} | ||
|
||
fun LzrValue.asLzrFunctionOrNull(): LzrFunction? { | ||
return asLzrTypeOrNull(Types.FUNCTION) | ||
} | ||
|
||
fun LzrValue.asLzrClassOrNull(): ClassInstanceValue? { | ||
return asLzrTypeOrNull(Types.CLASS) | ||
} | ||
|
||
inline fun <reified T : Any> LzrValue.asLzrTypeOrNull(targetType: Int): T? { | ||
if (isLzrType(targetType)) return this as T | ||
return null | ||
} |
Oops, something went wrong.
008a935
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ОООЙОЙОЙ все норм все в норме идея дура пон да