Changes made for the following:
1) Platform.java stays as abstract class with, but default implementation is removed. Stays in org.luaj.vm package
2) org.luaj.platform package is created to hold concrete Platform implementations
3) Platform.newLuaState() method is introduced to instantiate the LuaState. Other constructors are privatized.
4) Following Platform implementations are created:
J2sePlatform
J2meMidp20Cldc11Platform
J2meMidp10Cldc10Platform
5) All clients of luaj-vm are changed to include startup code that looks something like this:
Platform.setInstance( new J2meMidp20Cldc11Platform() );
LuaState state = Platform.getInstance().newLuaState();
This commit is contained in:
51
src/j2se/org/luaj/platform/J2sePlatform.java
Normal file
51
src/j2se/org/luaj/platform/J2sePlatform.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package org.luaj.platform;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
|
||||
import org.luaj.debug.net.j2se.DebugSupportImpl;
|
||||
import org.luaj.lib.j2se.LuajavaLib;
|
||||
import org.luaj.vm.DebugNetSupport;
|
||||
import org.luaj.vm.LDouble;
|
||||
import org.luaj.vm.LNumber;
|
||||
import org.luaj.vm.LuaState;
|
||||
import org.luaj.vm.Platform;
|
||||
|
||||
public class J2sePlatform extends Platform {
|
||||
public Reader createReader(InputStream inputStream) {
|
||||
return new InputStreamReader(inputStream);
|
||||
}
|
||||
|
||||
public DebugNetSupport getDebugSupport() throws IOException {
|
||||
DebugNetSupport debugNetSupport = new DebugSupportImpl(getDebugPort());
|
||||
return debugNetSupport;
|
||||
}
|
||||
|
||||
public String getProperty(String propertyName) {
|
||||
return System.getProperty(propertyName);
|
||||
}
|
||||
|
||||
protected void installOptionalLibs(LuaState vm) {
|
||||
vm.installStandardLibs();
|
||||
LuajavaLib.install(vm._G);
|
||||
}
|
||||
|
||||
public InputStream openFile(String fileName) {
|
||||
File file = new File(fileName);
|
||||
try {
|
||||
return new FileInputStream(file);
|
||||
} catch (FileNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public LNumber mathPow(double lhs, double rhs) {
|
||||
double d = Math.pow(lhs, rhs);
|
||||
return LDouble.valueOf(d);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user