view core/src/luan/init.luan @ 244:0a8e6fdb62f0

fix Math.random() git-svn-id: https://luan-java.googlecode.com/svn/trunk@245 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 09 Oct 2014 22:44:07 +0000
parents 1fada5587469
children 4dfa86dbca45
line wrap: on
line source

import "Package"
import "Basic"
import "Table"
import "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")
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 "java: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