Skip to content

Commit

Permalink
client: fix natives returns
Browse files Browse the repository at this point in the history
  • Loading branch information
xLuxy committed Sep 24, 2023
1 parent f028c4c commit a632e53
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions client/src/helpers/NativeInvoker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ bool js::NativeInvoker::PushArgs(js::FunctionContext& ctx, alt::INative* native)
{
using Type = alt::INative::Type;

CJavaScriptResource* resource = ctx.GetResource<CJavaScriptResource>();
std::vector<alt::INative::Type> nativeArgs = native->GetArgTypes();
int args = ctx.GetArgCount();

for(size_t i = 0; i < nativeArgs.size(); i++)
{
Expand Down Expand Up @@ -103,7 +101,7 @@ v8::Local<v8::Value> js::NativeInvoker::GetPointerReturnValue(alt::INative::Type
return resource->CreateVector3({ vector->x, vector->y, vector->z });
}
}
js::Logger::Warn("[JS] Unknown native pointer return type:", magic_enum::enum_name(type), (int)type);
// js::Logger::Warn("[JS] Unknown native pointer return type:", magic_enum::enum_name(type), (int)type);
return v8::Undefined(resource->GetIsolate());
}

Expand Down Expand Up @@ -170,10 +168,17 @@ bool js::NativeInvoker::Invoke(js::FunctionContext& ctx, alt::INative* native)
// todo: maybe v2 should move away from this array shit
js::Array arr{ invoker.returnsCount };

invoker.pointersCount = 0;

// First element is always the return value
arr.Push(invoker.GetReturnValue());

// Then push the pointer arguments into the array
for(size_t i = 0; i < args.size(); i++) arr.Push(invoker.GetPointerReturnValue(args[i]));
for (auto& arg : args)
{
if (auto val = invoker.GetPointerReturnValue(arg); !val->IsUndefined())
arr.Push(val);
}

ctx.Return(arr);
}
Expand Down

0 comments on commit a632e53

Please sign in to comment.