Byte Ptr to Type...how?

BlitzMax Forums/BlitzMax Programming/Byte Ptr to Type...how?

Is there any way to cast or convert a byte pointer to a type? Lua has a function "lua_newuserdata()" that returns a byte pointer to a chunk of data which holds your object.

Ideally, I'd like to be able to do the following:
Type testtype
Field name$
Field inta:Int[]
EndType

Global tt:testtype  

tt = testtype(lua_newuserdata(ls, SizeOf(testtype))) 'trying to cast here gives the error "Unable to convert from
 'byte pointer to <unknown>"



Is this in any way possible?

If not, ugh, the alternative is going to be bulky and slow.

Isn't tt the byte ptr to the typedata anyway?

The problem is the assignment of the new object to tt.

You need to do something like this :-

Function CreateTestType:testtype( ls )
Local tt:testtype = new testtype
inta = lua_newuserdata(ls, SizeOf(testtype))
Return tt
End Function

tt = CreateTestType()