From b639a3ca3ec7a668ec2ea7efd2296dd54773f375 Mon Sep 17 00:00:00 2001 From: James Roseborough Date: Wed, 3 Dec 2008 06:07:29 +0000 Subject: [PATCH] Add sample startup code for j2se --- README.html | 16 +++++++++++++--- src/sample/org/luaj/sample/SampleJ2seMain.java | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/sample/org/luaj/sample/SampleJ2seMain.java diff --git a/README.html b/README.html index e2393e2e..a3a481cd 100644 --- a/README.html +++ b/README.html @@ -14,7 +14,6 @@

-Add Multimedia Data Getting Started with LuaJ

@@ -76,8 +75,9 @@ The following pattern is used within J2SE import org.luaj.vm.*; String script = "main.lua"; - Platform.setPlatform( new J2sePlatform() ); + Platform.setInstance( new J2sePlatform() ); LuaState vm = Platform.newLuaState(); + org.luaj.compiler.LuaC.install(); vm.getglobal( "dofile" ); vm.pushstring( script ); vm.call( 1, 0 ); @@ -86,6 +86,12 @@ The following pattern is used within J2SE

You must include the library lib/luaj-j2se-${VER}.jar in your class path. +

+A working example may be found in +

+	src/sample/SampleJ2seMain.java
+
+

Additional usage may be found in

@@ -102,8 +108,9 @@ The following pattern is used within MIDlets:
 	import org.luaj.vm.*;
 
 	String script = "main.lua";
-	Platform.setPlatform( new J2mePlatform() );
+	Platform.setInstance( new J2meMidp20Cldc11Platform( midlet ) );
 	LuaState vm = Platform.newLuaState();
+	org.luaj.compiler.LuaC.install();
 	vm.getglobal( "dofile" );
 	vm.pushstring( script );
 	vm.call( 1, 0 );
@@ -128,6 +135,9 @@ but before the script is executed:
 	org.luaj.compiler.LuaC.install();
 
+

+To omit the compiler, omit this line from your startup code. +

Run a script using JSR-233 Dynamic Scripting

diff --git a/src/sample/org/luaj/sample/SampleJ2seMain.java b/src/sample/org/luaj/sample/SampleJ2seMain.java new file mode 100644 index 00000000..c23bbeea --- /dev/null +++ b/src/sample/org/luaj/sample/SampleJ2seMain.java @@ -0,0 +1,16 @@ +package org.luaj.sample; +import org.luaj.platform.*; +import org.luaj.vm.*; + +public class SampleJ2seMain { + + public static void main(String[] args) { + String script = (args.length>0? args[0]: "src/test/res/swingapp.lua"); + Platform.setInstance( new J2sePlatform() ); + LuaState vm = Platform.newLuaState(); + org.luaj.compiler.LuaC.install(); + vm.getglobal( "dofile" ); + vm.pushstring( script ); + vm.call( 1, 0 ); + } +}