Skip to main content
GameDev.net gamedev.net
✓ Solved

Angelscript equivalent of C++ void*

Started by tbaggeroftheuk Thursday at 7:25 PM 2 replies 100+ views
Original Post
tbaggeroftheuk
tbaggeroftheuk

For my game engine I'm trying to bind my VFS to AngelScript.
From what I've read, there's no direct equivalent to the C++:

void*

So before I try anything else I thought I'd ask here.

These are the two C++ member functions that I want to bind:

bool Write(const void* buffer, size_t bytes);
bool Read(void* buffer, size_t bytes);


I know you can do a uint8 array but I feel like that is a bit clunky.

Some relevant links to the source:
https://github.com/Cattle-Engine/Runtime/blob/main/include/engine/common/fs/file_provider.hpp
https://github.com/Cattle-Engine/Runtime/blob/main/include/engine/scripting/bindings/vfs/as_ifile.hpp
https://github.com/Cattle-Engine/Runtime/blob/main/include/engine/common/fs/vfs.hpp

(EDIT: Modified to remove the Markdown style code blocks)

Accepted Answer

Correct, there is no native equivalent of void* in AngelScript.

If you want to expose something like that to AngelScript all you need to do is to register it as a type, e.g.

engine->RegisterObjectType("void_ptr", sizeof(void*), asOBJ_VALUE | asOBJ_VALUE_POD | asOBJ_APP_PRIMITIVE);

You'll need to register the proper behaviors to manage the memory that the pointer is referring to. For example a constructor behavior to make it null by default.

If you don't want the user to be able to store a pointer that can be accessed at anytime you'll need to handle reference counting and/or back references so you have proper control over where the memory is accessed from.


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
tbaggeroftheuk
tbaggeroftheuk

WitchLord wrote:


Okie dokie, thank you so much for the info 😀

Sign in to reply to this topic.