🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Need to make an int32_t pointer inout, how do?

Started by
3 comments, last by WitchLord 9 months, 1 week ago

I have a function in my program, which is declared as the following:

int32_t seed_krand(int32_t* seed)
{
    *seed = (*seed * 1664525ul) + 221297ul;
    return ((uint32_t)*seed) >> 16;
}

As you can see, it takes a seed, cycles it, and then returns the result shifted right.

I need to be able to feed it a variable as a seed in angelscript, and have the cycled seed spit back into it, but I can't seem to make an argument of type int32 &inout. So, how would I set this up? I've read in the documentation it only works with reference types, but I don't know how to set it up in this context, would someone be able to help me?

None

Advertisement

Why are you writing a random number generator, is it homework?

@Alberth How is that relevant? And what even gave you that idea? No, I'm not writing a random number generator. This is an RNG function in an engine I'm working in, that I'm trying to expose to AngelScript. I posted the full function to give additional context of how it's being used.

None

By default this function cannot be registered with AngelScript as the lifetime of a primitive cannot always be guaranteed throughout a functioncall.

There are two options for you:

1) write a wrapper function and register that instead:

int32_t wrapper_seed_krand(int32_t seedIn, int32_t &seedOut)
{
	seedOut = seedIn;
	return seed_krand(&seedOut);
}
engine->RegisterGlobalFunction("int32 seed_krand(int32 seedIn, int32 &out seedOut)", asFUNCTION(wrapper_seed_krand), asCALL_CDECL);

2) enable unsafe references, and then register the original function:

engine->SetEngineProperty(asEP_ALLOW_UNSAFE_REFERENCES, true);
engine->RegisterGlobalFunction("int32 seed_krand(int32 &seed)", asFUNCTION(seed_krand), asCALL_CDECL);

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement