asqbtcupid / unreal.lua

lua solution for UnrealEngine4
MIT License
300 stars 98 forks source link

C++ call lua, param has struct, lua error #19

Closed mirchd closed 6 years ago

mirchd commented 6 years ago

struct XX_API FRect2D { GENERATED_BODY()

UPROPERTY()
FVector2D origin;

UPROPERTY()
FVector2D size;

}

FRect2D test FRect2D pInfo = &test; ... LuaCall("openInfoUI", this, pInfo);

.lua

function openInfoUI(info) local tmpOri = info:luaGet_origin() local tmpX = info:luaGet_origin():luaGet_X() end


error: attempt to call method 'LuaGet_X' (a nil value)...


on lua debug, the value of origin from "tmpOri" is wrong. the meta strcut of tmpOri is not FVector2D,which is FRect2D now.

please help,

asqbtcupid commented 6 years ago

wow, It's real a bug. for now,you can add some data to rect2d,i will fix it later.

struct XX_API FRect2D
{
GENERATED_BODY()

UPROPERTY()
FVector2D dummy;

UPROPERTY()
FVector2D origin;

UPROPERTY()
FVector2D size;
}
mirchd commented 6 years ago

UPROPERTY() FVector2D dummy; some other user define struct is also need to add these lines? how it cause this bug?

asqbtcupid commented 6 years ago

because the address of FRect2D is the same as FRect2D.origin. So when you get the origin,the lua treat it as FRect2D. This bug happen only when you get the first member of a struct, and the type of the member is a struct too. I will fix it tonight.

mirchd commented 6 years ago

understood I'll modify my code,thanks

asqbtcupid commented 6 years ago

fixed