Lua-Reflection bug

BlitzMax Forums/BlitzMax Programming/Lua-Reflection bug

JoshK(Posted 2009) [#1]
Functions with more than seven arguments cause a crash:
Import "lua-reflection.bmx"

Type TLuaMethods {expose static noclass}

	Method testfunc7:Int(p0#,p1#,p2#,p3#,p4#,p5#,p6#)
	EndMethod

	Method testfunc8:Int(p0#,p1#,p2#,p3#,p4#,p5#,p6#,p7#)
	EndMethod

EndType

Local L:Byte Ptr=luaL_newstate()
lua_implementtypes(L)

'This is fine
luaL_dostring(L,"testfunc7(0,0,0,0,0,0,0)")

'This crashes
luaL_dostring(L,"testfunc8(0,0,0,0,0,0,0,0)")



N(Posted 2009) [#2]
This is an issue with Brl.Reflection. Nothing I can do about it without moving it all to using FFI or modifying the reflection module.


JoshK(Posted 2009) [#3]
Can you explain more? Why would 7 arguments be fine, and 8 cause a crash?


N(Posted 2009) [#4]
Because 8 arguments (counting Self) is all the reflection code accounts for. The _Call function in reflection.bmx, starts on line 153, should more or less explain it.


JoshK(Posted 2009) [#5]
Here is my modification, with original code commented out:
Function _Call:Object( p:Byte Ptr,typeId:TTypeId,obj:Object,args:Object[],argTypes:TTypeId[] )
	'Local q[10],sp:Byte Ptr=q
	Local q[13],sp:Byte Ptr=q
	bbRefPushObject sp,obj
	sp:+4
	If typeId=LongTypeId sp:+8
	For Local i=0 Until args.length
		If Int Ptr(sp)>=Int Ptr(q)+8+3 Throw "ERROR"
		sp=_Push( sp,argTypes[i],args[i] )
	Next
	If Int Ptr(sp)>Int Ptr(q)+8+3 Throw "ERROR"
	Select typeId
		Case ByteTypeId,ShortTypeId,IntTypeId
			Local f(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10)=p
			Return String.FromInt( f( q[0],q[1],q[2],q[3],q[4],q[5],q[6],q[7],q[8],q[9],q[10] ) )
			'Local f(p0,p1,p2,p3,p4,p5,p6,p7)=p
			'Return String.FromInt( f( q[0],q[1],q[2],q[3],q[4],q[5],q[6],q[7] ) )
		Case LongTypeId
			Throw "TODO"
		Case FloatTypeId
			Local f:Float(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10)=p
			Return String.FromFloat( f( q[0],q[1],q[2],q[3],q[4],q[5],q[6],q[7],q[8],q[9],q[10] ) )
			'Local f:Float(p0,p1,p2,p3,p4,p5,p6,p7)=p
			'Return String.FromFloat( f( q[0],q[1],q[2],q[3],q[4],q[5],q[6],q[7] ) )
		Case DoubleTypeId
			Local f:Float(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10)=p
			Return String.FromDouble( f( q[0],q[1],q[2],q[3],q[4],q[5],q[6],q[7],q[8],q[9],q[10] ) )			
			'Local f:Double(p0,p1,p2,p3,p4,p5,p6,p7)=p
			'Return String.FromDouble( f( q[0],q[1],q[2],q[3],q[4],q[5],q[6],q[7] ) )
		Default
			Local f:Object(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10)=p
			Return f( q[0],q[1],q[2],q[3],q[4],q[5],q[6],q[7],q[8],q[9],q[10] )
			'Local f:Object(p0,p1,p2,p3,p4,p5,p6,p7)=p
			'Return f( q[0],q[1],q[2],q[3],q[4],q[5],q[6],q[7] )
	End Select
End Function