[`-D scriptable`]: functions with raw pointer arguments or return type don't compile

Open
#1,222 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
compilers

Research direction

Start with the generated C++ snippets for -D scriptable and trace StackContext::runObject, StackContext::getObject, and StackContext::returnObject. Reproduce the raw-pointer and defined-type cases using hxvlc or hxdiscord_rpc, then inspect how generated wrappers pass and return values. Done means these signatures compile without invalid Dynamic-to-pointer or defined-type conversions.

Written by the indexing model from the issue text.

Description

I have noticed an issue when compiling a project with -D scriptable that uses hxvlc and hxdiscord_rpc.
Seemingly functions that have arguments that are raw pointers or a return type that is a raw pointer, don't compile.
Also functions that return a defined type from raw cpp code, also don't compile.

For example: It tries to cast Dynamic to void*, which isn't possible. The reason this happens is because it uses StackContext::runObject and StackContext::getObject return Dynamic.

generated cpp code snippets:

void* videoLock( void** planes ) {
	if (__scriptVTable[140] ) {
		::hx::CppiaCtx *__ctx = ::hx::CppiaCtx::getCurrent();
		::hx::AutoStack __as(__ctx);
		__ctx->pushObject(this);
		__ctx->pushObject(planes);
		return __ctx->runObject(__scriptVTable[140] ); // returns Dynamic, but we need void*
	}  else return Video_obj::videoLock(planes);return null();}

// ...

template<bool _HX_SUPER=false>
static void CPPIA_CALL __s_videoLock(::hx::CppiaCtx *ctx) {
ctx->returnObject( _HX_SUPER ? ((Video_obj*)ctx->getThis())->Video_obj::videoLock(ctx->getObject(sizeof(void*))) : ((Video_obj*)ctx->getThis())->videoLock(ctx->getObject(sizeof(void*))));
}
 DiscordRichPresence buildPresence(  ::Dynamic params ) {
if (__scriptVTable[6] ) {
	::hx::CppiaCtx *__ctx = ::hx::CppiaCtx::getCurrent();
	::hx::AutoStack __as(__ctx);
	__ctx->pushObject(this);
	__ctx->pushObject(params);
	return __ctx->runObject(__scriptVTable[6] ); // returns Dynamic, but we need DiscordRichPresence
}  else return DiscordClient_obj::buildPresence(params);return null();}

// ...

template<bool _HX_SUPER=false>
static void CPPIA_CALL __s_buildPresence(::hx::CppiaCtx *ctx) {
ctx->returnObject( _HX_SUPER ? ((DiscordClient_obj*)ctx->getThis())->DiscordClient_obj::buildPresence(ctx->getObject(sizeof(void*))) : ((DiscordClient_obj*)ctx->getThis())->buildPresence(ctx->getObject(sizeof(void*))));
}
Dominant language
C++
Stars
330
Forks
237
Avg merge
1d 3h
Merged PRs (30d)
20

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from HaxeFoundation/hxcpp

All issues in HaxeFoundation/hxcpp

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.