<commit_before>local somemodule = require 'module.some'
import "UnityEngine"

if not UnityEngine.GameObject then
	error("Click Make/All to generate lua wrap file")
end


MyVector3=Slua.Class(Vector3,
	nil, --static function
	{ --instance member function
		Normalize=function(self)
			print "overloaded Normalize"
			local l=math.sqrt(self.x*self.x+self.y*self.y,self.z*self.z)
			self.x=self.x/l
			self.y=self.y/l
			self.z=self.z/l
		end,

	}
)

My2=Slua.Class(MyVector3,nil,nil)

MyGameObject=Slua.Class(GameObject,
	nil,
	{
		AddComponent=function(self,t)
			print "overloaded AddComponent"
			self.__base:AddComponent(t)
		end,
	}	
)


function main()

	if jit then
		print("using luajit ",jit.version,jit.arch)
	else
		print("using lua")
	end

	-- test custom component
	local x=UnityEngine.GameObject("OoOo")
	x:AddComponent(SLuaTest)
	local c=x:GetComponent(SLuaTest)
	print("test monobehaviour",c, c.transform, c:GetType().Name)
	assert(c.gameObject.name=="OoOo")
	local c=x:GetComponent(UnityEngine.BoxCollider)
	assert(c==null)

	local ll=XXList() -- it's List<int>
	ll:Add(1)
	print(ll.Count)

	-- test inherite class
	local mv = My2(1,2,3)
	mv:Normalize()
	print(mv.x,mv.y,mv.z)
	mv:Set(0,0,0)
	print(mv.x,mv.y,mv.z)

	local x=MyGameObject("MyGameObject")
	x:AddComponent(SphereCollider)
	HelloWorld.ofunc(x)

	-- test value type
	local x=Vector3(3,3,3)
	x:Normalize()
	print(x.x,x.y,x.z)
	x=-x
	print(x.x,x.y,x.z)

	local c=Color(1,1,1,1)
	print("color",c.r)
	local fs=foostruct()
	fs.mode=1
	fs.x=11.1
	assert(fs.mode==1)

	-- test module require
	print(somemodule.add(2,3))

	local go = GameObject.Find("Canvas/Button")
	local btn = go:GetComponent("Button")

	local Canvas = GameObject.Find("Canvas")
	-- foreach
	for t in Slua.iter(Canvas.transform) do
		print("foreach transorm",t)
	end
	
	-- bytes return byte[]
	local data = HelloWorld.bytes()
	print("data type ",type(data))
	data = Slua.ToString(data)
	print("data type ",type(data),data)

	-- get out parameter
	local ok,hitinfo = Physics.Raycast(Vector3(0,0,0),Vector3(0,0,1),Slua.out)
	print("Physics Hitinfo",ok,hitinfo)
	

	btn.onClick:AddListener(function()
		local go = GameObject.Find("Canvas/Text")
		local label = go:GetComponent("Text")
		label.text="hello world"
	end)
	

	local go = GameObject.Find("Canvas/Panel2"):GetComponent("ScrollRect")
	local go2 = GameObject.Find("Canvas/Panel2"):GetComponent("ScrollRect")
	assert(go==go2)

	go.onValueChanged:AddListener(function(v)
		print("scroll value changed",v.x,v.y)
	end)

	local cube = GameObject.CreatePrimitive(UnityEngine.PrimitiveType.Cube)
	local cube2 = GameObject.CreatePrimitive(UnityEngine.PrimitiveType.Cube)
	local mat = cube:GetComponent(Renderer).material
	mat.color=Color.red

	cube.name="Script cube"
	cube2.name="Script cube2"

	cube.transform:SetParent(cube2.transform)

	local pos = Vector3(10,10,10)+Vector3(1,1,1)
	cube.transform.position = pos
	cube.transform.localScale = Vector3(10,10,10)
	print("cube==cube2",cube==cube2)
	assert(cube.transform==cube.transform)

	LuaTimer.Add(0,20,function(id)
		cube.transform.localScale = Vector3(10,10,10)*(0.1+math.sin(Time.time))
		cube2.transform.position = Vector3(math.sin(Time.time)*5,0,0)
		cube.transform.localRotation = Quaternion.Euler(0,0,math.sin(Time.time)*90)
		return true
	end)

	print(UnityEngine.PrimitiveType.Cube,type(UnityEngine.PrimitiveType.Cube))


	print("LogCallback occured",n)

	local c=coroutine.create(function()

		print "coroutine start"

		Yield(WaitForSeconds(2))
		print "coroutine WaitForSeconds 2"

		local www = WWW("http://www.sineysoft.com")
		Yield(www)
		print(#Slua.ToString(www.bytes))

		local y = HelloWorld()
		local y = y:y()
		Yield(y)
		print("Yield ok")
	end)
	coroutine.resume(c)

	-- test lua table
	HelloWorld.setv({name="yes",value=12})
	local t=HelloWorld.getv()
	for k,v in pairs(t) do
		print("table value",k,v)
	end

	-- test overload func
	HelloWorld.ofunc(GameObject)
	HelloWorld.ofunc(cube)

	-- test variant number args
	HelloWorld.func6("aa",1,2)
	HelloWorld.func6("aa",1,2,3,"bb")
	HelloWorld.func6("aa",1,2,3,"bb",true,false)
	HelloWorld.func6("aa")
	local ss=String("bb")
	HelloWorld.func6(ss,1,2) -- func6 accpet system.string as 1st parameter, you can pass "xx" or String("xx")
	assert(ss~="bb") -- bb is luastring, ss is System.String
	
	-- test luafunction
	local h=HelloWorld()
	h:func7(abc)
end

function abc()
	print("call func7 callback")
end

function foo(a,b,c)
	return a,b,c,"slua"
end

function str()
	return "slua"
end

return 1,2,3
<commit_msg> update main<commit_after>local somemodule = require 'module.some'
import "UnityEngine"

if not UnityEngine.GameObject then
	error("Click Make/All to generate lua wrap file")
end


MyGameObject=Slua.Class(GameObject,
	nil,
	{
		AddComponent=function(self,t)
			print "overloaded AddComponent"
			self.__base:AddComponent(t)
		end,
	}	
)


function main()

	if jit then
		print("using luajit ",jit.version,jit.arch)
	else
		print("using lua")
	end

	HelloWorld.depth= "a"
	print(HelloWorld.depth)
	HelloWorld.priority=1
	print(HelloWorld.priority)

	-- test custom component
	local x=UnityEngine.GameObject("OoOo")
	x:AddComponent(SLuaTest)
	local c=x:GetComponent(SLuaTest)
	print("test monobehaviour",c, c.transform, c:GetType().Name)
	assert(c.gameObject.name=="OoOo")
	local c=x:GetComponent(UnityEngine.BoxCollider)
	assert(c==null)

	local ll=XXList() -- it's List<int>
	ll:Add(1)
	print(ll.Count)

	local x=MyGameObject("MyGameObject")
	x:AddComponent(SphereCollider)
	HelloWorld.ofunc(x)

	-- test value type
	local x=Vector3(3,3,3)
	x:Normalize()
	print(x.x,x.y,x.z)
	x=-x
	print(x.x,x.y,x.z)

	local c=Color(1,1,1,1)
	print("color",c.r)
	local fs=foostruct()
	fs.mode=1
	fs.x=11.1
	assert(fs.mode==1)

	-- test module require
	print(somemodule.add(2,3))

	local go = GameObject.Find("Canvas/Button")
	local btn = go:GetComponent("Button")

	local Canvas = GameObject.Find("Canvas")
	-- foreach
	for t in Slua.iter(Canvas.transform) do
		print("foreach transorm",t)
	end
	
	-- bytes return byte[]
	local data = HelloWorld.bytes()
	print("data type ",type(data))
	data = Slua.ToString(data)
	print("data type ",type(data),data)

	-- get out parameter
	local ok,hitinfo = Physics.Raycast(Vector3(0,0,0),Vector3(0,0,1),Slua.out)
	print("Physics Hitinfo",ok,hitinfo)
	

	btn.onClick:AddListener(function()
		local go = GameObject.Find("Canvas/Text")
		local label = go:GetComponent("Text")
		label.text="hello world"
	end)
	

	local go = GameObject.Find("Canvas/Panel2"):GetComponent("ScrollRect")
	local go2 = GameObject.Find("Canvas/Panel2"):GetComponent("ScrollRect")
	assert(go==go2)

	go.onValueChanged:AddListener(function(v)
		print("scroll value changed",v.x,v.y)
	end)

	local cube = GameObject.CreatePrimitive(UnityEngine.PrimitiveType.Cube)
	local cube2 = GameObject.CreatePrimitive(UnityEngine.PrimitiveType.Cube)
	local mat = cube:GetComponent(Renderer).material
	mat.color=Color.red

	cube.name="Script cube"
	cube2.name="Script cube2"

	cube.transform:SetParent(cube2.transform)

	local pos = Vector3(10,10,10)+Vector3(1,1,1)
	cube.transform.position = pos
	cube.transform.localScale = Vector3(10,10,10)
	print("cube==cube2",cube==cube2)
	assert(cube.transform==cube.transform)

	LuaTimer.Add(0,20,function(id)
		cube.transform.localScale = Vector3(10,10,10)*(0.1+math.sin(Time.time))
		cube2.transform.position = Vector3(math.sin(Time.time)*5,0,0)
		cube.transform.localRotation = Quaternion.Euler(0,0,math.sin(Time.time)*90)
		return true
	end)

	print(UnityEngine.PrimitiveType.Cube,type(UnityEngine.PrimitiveType.Cube))


	print("LogCallback occured",n)

	local c=coroutine.create(function()

		print "coroutine start"

		Yield(WaitForSeconds(2))
		print "coroutine WaitForSeconds 2"

		local www = WWW("http://www.sineysoft.com")
		Yield(www)
		print(#Slua.ToString(www.bytes))

		local y = HelloWorld()
		local y = y:y()
		Yield(y)
		print("Yield ok")
	end)
	coroutine.resume(c)

	-- test lua table
	HelloWorld.setv({name="yes",value=12})
	local t=HelloWorld.getv()
	for k,v in pairs(t) do
		print("table value",k,v)
	end

	-- test overload func
	HelloWorld.ofunc(GameObject)
	HelloWorld.ofunc(cube)

	-- test variant number args
	HelloWorld.func6("aa",1,2)
	HelloWorld.func6("aa",1,2,3,"bb")
	HelloWorld.func6("aa",1,2,3,"bb",true,false)
	HelloWorld.func6("aa")
	local ss=String("bb")
	HelloWorld.func6(ss,1,2) -- func6 accpet system.string as 1st parameter, you can pass "xx" or String("xx")
	assert(ss~="bb") -- bb is luastring, ss is System.String
	
	-- test luafunction
	local h=HelloWorld()
	h:func7(abc)
end

function abc()
	print("call func7 callback")
end

function foo(a,b,c)
	return a,b,c,"slua"
end

function str()
	return "slua"
end

return 1,2,3

{'fraction_non_alphanumeric': 0.15547135147548513, 'fraction_numerical': 0.02411298656562177, 'mean_word_length': 5.1598302687411595, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '218941', 'n_tokens_mistral': 3587, 'n_tokens_neox': 3423, 'n_words': 601}