External class with function, export problem

Monkey Forums/Monkey Bug Reports/External class with function, export problem

Kalakian(Posted 2012) [#1]
It appears as though trans doesn't handle external classes with a static method (Function) in them correctly. Consider the following simple example:

Function Main:Int()
	If(MyClass.doesThisWork())
		Print("It worked!")
	EndIf
	Return 0
End

Class MyClass
	Function doesThisWork:Bool()
		Return True
	End
End


This works as expected, and the line
MyClass.doesThisWork()
is exported as
bb_TestProj_MyClass.g_doesThisWork()
(Flash) or
bb__MyClass.g_doesThisWork()
(XNA)

Now, keeping Main the same, alter the class definition to be external:

Function Main:Int()

	If(MyClass.doesThisWork())
		Print("It worked!")
	EndIf
	Return 0
End

Extern

Class MyClass
	Function doesThisWork:Bool()
End


With the appropriately defined external code, this incorrectly exports the line
MyClass.doesThisWork()
as
doesThisWork()
(same in Flash and XNA). The problem is that it sees an external function as being in the global scope, rather than a static method of a class.


marksibly(Posted 2012) [#2]
Hi,

This is a known issue and something I'd like to clean up eventually, but for now you'll just have to work around it - see databuffer.monkey in the opengl module for an example.

This is down to languages that don't really support 'scoped' statics (in particular html5). Well, they do, but at the cost of an extra runtime lookup (probably not worth worrying about) but IMO the better fix is to do something clever with symbol munging. Not sure what yet...