changeset 298:2ce23c7e2342

remove init.luan git-svn-id: https://luan-java.googlecode.com/svn/trunk@299 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Tue, 16 Dec 2014 03:51:56 +0000
parents 899253043270
children a74559240b4f
files core/src/luan/LuanState.java core/src/luan/init.luan core/src/luan/modules/Basic.luan core/src/luan/modules/Debug.luan core/src/luan/modules/Io.luan core/src/luan/modules/Package.luan
diffstat 6 files changed, 93 insertions(+), 90 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/LuanState.java	Tue Dec 16 03:26:43 2014 +0000
+++ b/core/src/luan/LuanState.java	Tue Dec 16 03:51:56 2014 +0000
@@ -60,7 +60,8 @@
 	public static LuanState newStandard() {
 		try {
 			LuanState luan = LuanCompiler.newLuanState();
-			BasicLuan.do_file(luan,"classpath:luan/init.luan");
+			PackageLuan.require(luan,"luan:Basic");
+//			BasicLuan.do_file(luan,"classpath:luan/init.luan");
 			return luan;
 		} catch(LuanException e) {
 			throw new RuntimeException(e);
--- a/core/src/luan/init.luan	Tue Dec 16 03:26:43 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,89 +0,0 @@
-import "luan:Package"
-import "luan:Basic"
-import "luan:Table"
-import "luan:Io"
-
-function Package.global(module,fn_name)
-	local function fn(...)
-		return module[fn_name](...)
-	end
-	_G[fn_name] = fn
-	return fn
-end
-
-local require = Package.global(Package,"require")
-Package.global(Basic,"assert")
-Package.global(Basic,"assert_boolean")
-Package.global(Basic,"assert_nil")
-Package.global(Basic,"assert_number")
-Package.global(Basic,"assert_string")
-Package.global(Basic,"assert_table")
-Package.global(Basic,"assert_integer")
-Package.global(Basic,"assert_long")
-local do_file = Package.global(Basic,"do_file")
-Package.global(Basic,"error")
-Package.global(Basic,"get_metatable")
-Package.global(Basic,"ipairs")
-local load = Package.global(Basic,"load")
-Package.global(Basic,"load_file")
-Package.global(Basic,"pairs")
-Package.global(Basic,"range")
-Package.global(Basic,"raw_equal")
-Package.global(Basic,"raw_get")
-Package.global(Basic,"raw_len")
-Package.global(Basic,"raw_set")
-Package.global(Basic,"repr")
-Package.global(Basic,"set_metatable")
-Package.global(Basic,"to_boolean")
-Package.global(Basic,"to_number")
-local to_string = Package.global(Basic,"to_string")
-Package.global(Basic,"type")
-
-do_file "classpath:luan/version.luan"
-
-
-function Io.print_to(out,...)
-	local list = {}
-	for _,v in Basic.values(...) do
-		list[#list+1] = to_string(v)
-		list[#list+1] = '\t'
-	end
-	if #list == 0 then
-		out.write( '\n' )
-	else
-		list[#list] = '\n'
-		out.write( Table.unpack(list) )
-	end
-end
-
-function Basic.print(...)
-	Io.print_to(Io.stdout,...)
-end
-local print = Package.global(Basic,"print")
-
-local Debug = {}
-Package.loaded.Debug = Debug
-_G.Debug = Debug
-
-function Debug.print_if_something(...)
-	if Table.pack(...).n > 0 then
-		print(...)
-	end
-end
-
-function Debug.debug(prompt)
-	prompt = prompt or "luan_debug> "
-	local function console()
-		return Io.read_console_line(prompt)
-	end
-	local env = {}
-	for line in console do
-		try
-			local fn = load(line,"stdin",env,true)
-			Debug.print_if_something( fn() )
-		catch e do
-			print(e)
-		end
-	end
-end
-
--- a/core/src/luan/modules/Basic.luan	Tue Dec 16 03:26:43 2014 +0000
+++ b/core/src/luan/modules/Basic.luan	Tue Dec 16 03:51:56 2014 +0000
@@ -27,3 +27,37 @@
 to_string = BasicLuan.to_string
 type = BasicLuan.type
 values = BasicLuan.values
+
+
+import "luan:Package"
+local Basic = _ENV
+
+Package.global(Package,"require")
+Package.global(Basic,"assert")
+Package.global(Basic,"assert_boolean")
+Package.global(Basic,"assert_nil")
+Package.global(Basic,"assert_number")
+Package.global(Basic,"assert_string")
+Package.global(Basic,"assert_table")
+Package.global(Basic,"assert_integer")
+Package.global(Basic,"assert_long")
+Package.global(Basic,"do_file")
+Package.global(Basic,"error")
+Package.global(Basic,"get_metatable")
+Package.global(Basic,"ipairs")
+Package.global(Basic,"load")
+Package.global(Basic,"load_file")
+Package.global(Basic,"pairs")
+Package.global(Basic,"range")
+Package.global(Basic,"raw_equal")
+Package.global(Basic,"raw_get")
+Package.global(Basic,"raw_len")
+Package.global(Basic,"raw_set")
+Package.global(Basic,"repr")
+Package.global(Basic,"set_metatable")
+Package.global(Basic,"to_boolean")
+Package.global(Basic,"to_number")
+Package.global(Basic,"to_string")
+Package.global(Basic,"type")
+
+do_file "classpath:luan/version.luan"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/src/luan/modules/Debug.luan	Tue Dec 16 03:51:56 2014 +0000
@@ -0,0 +1,25 @@
+import "luan:Table"
+
+
+function print_if_something(...)
+	if Table.pack(...).n > 0 then
+		print(...)
+	end
+end
+
+function debug(prompt)
+	prompt = prompt or "luan_debug> "
+	local function console()
+		return Io.read_console_line(prompt)
+	end
+	local env = {}
+	for line in console do
+		try
+			local fn = load(line,"stdin",env,true)
+			print_if_something( fn() )
+		catch e do
+			print(e)
+		end
+	end
+end
+
--- a/core/src/luan/modules/Io.luan	Tue Dec 16 03:26:43 2014 +0000
+++ b/core/src/luan/modules/Io.luan	Tue Dec 16 03:51:56 2014 +0000
@@ -8,3 +8,27 @@
 socket_server = IoLuan.socket_server
 stdout = IoLuan.textWriter(System.out)
 stderr = IoLuan.textWriter(System.err)
+
+
+import "luan:Package"
+import "luan:Basic"
+import "luan:Table"
+
+function print_to(out,...)
+	local list = {}
+	for _,v in Basic.values(...) do
+		list[#list+1] = to_string(v)
+		list[#list+1] = '\t'
+	end
+	if #list == 0 then
+		out.write( '\n' )
+	else
+		list[#list] = '\n'
+		out.write( Table.unpack(list) )
+	end
+end
+
+function Basic.print(...)
+	print_to(stdout,...)
+end
+Package.global(Basic,"print")
--- a/core/src/luan/modules/Package.luan	Tue Dec 16 03:26:43 2014 +0000
+++ b/core/src/luan/modules/Package.luan	Tue Dec 16 03:51:56 2014 +0000
@@ -3,3 +3,11 @@
 loaded = PackageLuan.loaded()
 require = PackageLuan.requireFn
 load = PackageLuan.load
+
+function global(module,fn_name)
+	local function fn(...)
+		return module[fn_name](...)
+	end
+	_G[fn_name] = fn
+	return fn
+end