[Refactoring] Converted some classes to kotlin in the BaseLua module

This commit is contained in:
hartie95 2023-11-13 05:53:57 +01:00
parent 7170d0ed5c
commit ff03ca7507
14 changed files with 113 additions and 225 deletions

View File

@ -1,9 +0,0 @@
package org.anime_game_servers.lua.engine;
import java.io.InputStream;
import java.nio.file.Path;
public interface BaseScriptLoader {
InputStream openScript(Path scriptPath);
Path getScriptPath(String scriptName);
}

View File

@ -0,0 +1,9 @@
package org.anime_game_servers.lua.engine
import java.io.InputStream
import java.nio.file.Path
interface BaseScriptLoader {
fun openScript(scriptPath: Path): InputStream?
fun getScriptPath(scriptName: String): Path?
}

View File

@ -1,24 +0,0 @@
package org.anime_game_servers.lua.engine;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.script.ScriptException;
import java.util.List;
import java.util.Map;
public interface LuaScript {
boolean hasMethod(@Nonnull String methodName);
@Nullable
LuaValue callMethod(@Nonnull String methodName, Object... args) throws ScriptException, NoSuchMethodException;
void evaluate() throws ScriptException;
<T> T getGlobalVariable(String name, Class<T> type);
<T> List<T> getGlobalVariableList(String name, Class<T> type);
<T> Map<String, T> getGlobalVariableMap(String name, Class<T> type);
LuaEngine getEngine();
}

View File

@ -0,0 +1,18 @@
package org.anime_game_servers.lua.engine
import javax.annotation.Nonnull
import javax.script.ScriptException
interface LuaScript {
fun hasMethod(@Nonnull methodName: String): Boolean
@Throws(ScriptException::class, NoSuchMethodException::class)
fun callMethod(@Nonnull methodName: String, vararg args: Any?): LuaValue?
@Throws(ScriptException::class)
fun evaluate()
fun <T> getGlobalVariable(name: String, type: Class<T>): T?
fun <T> getGlobalVariableList(name: String, type: Class<T>): List<T>
fun <T> getGlobalVariableMap(name: String, type: Class<T>): Map<String, T>
val engine: LuaEngine?
}

View File

@ -1,33 +0,0 @@
package org.anime_game_servers.lua.engine;
public interface LuaValue {
boolean isNull();
boolean isBoolean();
boolean isInteger();
boolean isLong();
boolean isDouble();
boolean isFloat();
boolean isString();
boolean isTable();
boolean asBoolean();
int asInteger();
long asLong();
double asDouble();
float asFloat();
String asString();
<T> T asObject(Class<T> type);
}

View File

@ -0,0 +1,19 @@
package org.anime_game_servers.lua.engine
interface LuaValue {
fun isNull() : Boolean
fun isBoolean() : Boolean
fun isInteger() : Boolean
fun isLong() : Boolean
fun isDouble() : Boolean
fun isFloat() : Boolean
fun isString() : Boolean
fun isTable() : Boolean
fun asBoolean(): Boolean
fun asInteger(): Int
fun asLong(): Long
fun asDouble(): Double
fun asFloat(): Float
fun asString(): String?
fun <T> asObject(type: Class<T>): T?
}

View File

@ -1,52 +0,0 @@
package org.anime_game_servers.lua.models;
public class BooleanLuaValue extends MockLuaValue {
public static final BooleanLuaValue TRUE = new BooleanLuaValue(true);
public static final BooleanLuaValue FALSE = new BooleanLuaValue(false);
private final boolean value;
public BooleanLuaValue(boolean value){
this.value = value;
}
@Override
public boolean isBoolean() {
return true;
}
@Override
public boolean asBoolean() {
return value;
}
@Override
public int asInteger() {
return value ? 1 : 0;
}
@Override
public long asLong() {
return value ? 1 : 0;
}
@Override
public double asDouble() {
return value ? 1 : 0;
}
@Override
public float asFloat() {
return value ? 1 : 0;
}
@Override
public String asString() {
return value ? "true" : "false";
}
@Override
public <T> T asObject(Class<T> type) {
if(type == Boolean.class)
return type.cast(value);
return null;
}
}

View File

@ -0,0 +1,23 @@
package org.anime_game_servers.lua.models
class BooleanLuaValue(private val value: Boolean) : MockLuaValue() {
override fun isBoolean() = true
override fun asBoolean() = value
override fun asInteger() = if (value) 1 else 0
override fun asLong() = if (value) 1L else 0L
override fun asDouble() = if (value) 1.0 else 0.0
override fun asFloat() = if (value) 1f else 0f
override fun asString() = value.toString()
override fun <T> asObject(type: Class<T>): T? {
return if (type == Boolean::class.java) type.cast(value) as T else null
}
companion object {
@JvmField
val TRUE = BooleanLuaValue(true)
@JvmField
val FALSE = BooleanLuaValue(false)
}
}

View File

@ -1,56 +0,0 @@
package org.anime_game_servers.lua.models;
public class IntLuaValue extends MockLuaValue {
public static final IntLuaValue ZERO = new IntLuaValue(0);
public static final IntLuaValue ONE = new IntLuaValue(1);
public static final IntLuaValue N_ONE = new IntLuaValue(-1);
private final int value;
public IntLuaValue(int value) {
this.value = value;
}
@Override
public boolean isInteger() {
return true;
}
@Override
public boolean asBoolean() {
return value != 0;
}
@Override
public int asInteger() {
return value;
}
@Override
public long asLong() {
return value;
}
@Override
public double asDouble() {
return value;
}
@Override
public float asFloat() {
return value;
}
@Override
public String asString() {
return Integer.toString(value);
}
@Override
public <T> T asObject(Class<T> type) {
if(type == Number.class)
return type.cast(value);
return null;
}
}

View File

@ -0,0 +1,25 @@
package org.anime_game_servers.lua.models
class IntLuaValue(private val value: Int) : MockLuaValue() {
override fun isInteger() = true
override fun asBoolean() = value != 0
override fun asInteger() = value
override fun asLong() = value.toLong()
override fun asDouble() = value.toDouble()
override fun asFloat() = value.toFloat()
override fun asString() = value.toString()
override fun <T> asObject(type: Class<T>): T? {
return if (type == Number::class.java) type.cast(value) as T? else null
}
companion object {
@JvmField
val ZERO = IntLuaValue(0)
@JvmField
val ONE = IntLuaValue(1)
@JvmField
val N_ONE = IntLuaValue(-1)
}
}

View File

@ -1,5 +0,0 @@
package org.anime_game_servers.lua.models;
public interface IntValueEnum {
int getValue();
}

View File

@ -0,0 +1,5 @@
package org.anime_game_servers.lua.models
interface IntValueEnum {
fun getValue(): Int
}

View File

@ -1,46 +0,0 @@
package org.anime_game_servers.lua.models;
import org.anime_game_servers.lua.engine.LuaValue;
public abstract class MockLuaValue implements LuaValue {
@Override
public boolean isNull() {
return false;
}
@Override
public boolean isBoolean() {
return false;
}
@Override
public boolean isInteger() {
return false;
}
@Override
public boolean isLong() {
return false;
}
@Override
public boolean isDouble() {
return false;
}
@Override
public boolean isFloat() {
return false;
}
@Override
public boolean isString() {
return false;
}
@Override
public boolean isTable() {
return false;
}
}

View File

@ -0,0 +1,14 @@
package org.anime_game_servers.lua.models
import org.anime_game_servers.lua.engine.LuaValue
abstract class MockLuaValue : LuaValue {
override fun isNull() = false
override fun isBoolean() = false
override fun isInteger() = false
override fun isLong() = false
override fun isDouble() = false
override fun isFloat() = false
override fun isString() = false
override fun isTable() = false
}