Byte Ptr to Type...how?

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

SculptureOfSoul(Posted 2006) [#1]
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.


tonyg(Posted 2006) [#2]
Isn't tt the byte ptr to the typedata anyway?


Brendane(Posted 2006) [#3]
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()