Some questions about native extensions


I got some problems when trying to write native extensions.
All libraries release for x64.
Version: 1.2.164

  1. We can get the buffer value using getbytes(). How can I write data to the buffer?
  2. I was building static libraries in MVSC 2019. Always got that message. I don’t know if I did anything wrong in Visual. But if build a dynamic library, everything works.

  3. If put dlls in res, then crash.

    (Sorry, that is not in English, but the meaning I think is clear. Crash.)
    But it’s okay if the dll is in the root.
    May need to bundle, but I tried with the dll in the res. Then error with a missing function from the library.

Dynamic in the project. Dll in the root and everything works.
Static: (605.9 KB)

Project: (9.2 MB)

No crashes and errors if the dynamic link library and dll in root



OBJ files are not supported, so Defold complains about them. Just don’t put them under the extension dir.

Did you write the actual extension? Bridge between Lua and ogg/vorbis libs.



Yeah. Without libraries extension works. And works if dinamic library. I did not have obj files, only lib. Sorry if I didn’t fully understand what you mean by obj. I mean .obj, but I built only .lib


  1. You pass in a void** which means it returns the pointer where the bytes are stored. Cast the pointer appropriately, and store your bytes directly.

  2. As @sergey.lerg mentioned, we only support .lib files. We recommend statically linked libraries. If you use dynamically linked libraries, we don’t support that in a very good manner yet, as you noticed, since we set a path to the .dll’s when doing Build and run. During the bundling step though, you can copy files if you use the project.bundle_resources property (see project settings)



Sorry, I do not understand 1.
local res = resource.load("/assets/sound.ogg")
I loss my full .cpp file. But there was something:
dmBuffer::HBuffer buffer;
dmScript::LuaHBuffer *lua_buffer = dmScript::CheckBuffer(L, 1);
buffer = lua_buffer->m_Buffer;
int size;
uint8_t* bytes;
dmBuffer::GetBytes(buffer, (void**)&bytes, &size);
//If I write bytes to file, then I get same as I pass to res.load

I seem to have begun to understand, do I need to change the values ​​in bytes?



I have bytes. It’s ogg file. When I convert, I get wav file. I can’t write it in buffer, because other size. Right?



That is a correct way to load an asset from the bundled assets, and getting hold of the data in C++.

If I write bytes to file, then I get same as I pass to res.load

Yes, that should be the full contents of the .ogg file.

Not sure what you mean?

1 Like


I don’t know, how change buffer. I want some like:
local res = resource.load("/assets/sound.ogg")
.ogg file in res
Now .wav in res

I don’t know, how write wav in buffer, where ogg.
Does the buffer have a fixed size? If so, how to change it or recreate buffer.



Since the conversion will most likely need a different number of bytes, you need to create a new buffer to store your wav buffer to. Using dmBuffer::GetBytes() you’ll get both the pointer to the source bytes and a pointer to where to store the destination bytes.

As for the actual wav conversion, you’ll need to see the api of the framework you are using for the conversion.

A question though: Why convert to .wav? We support playing both .ogg and .wav, but there’s a benefit of smaller disc size when using .ogg and also faster playback on devices.

1 Like

In one of my functions, calculations occur and because of this freeze the sound. I started using OpenAL, but it only supports wav, which is large in size. I want to store files in ogg, and before transferring to OpenAL, convert them to wav.

I’ll try use dmBuffer :: Create (). Thanks.



Everything worked out. Implemented so:

const dmBuffer::StreamDeclaration streams_decl[] = 
	{dmHashString64("byte"), dmBuffer::VALUE_TYPE_UINT8, 1},

dmBuffer::Result r_create = dmBuffer::Create(out_size, streams_decl, 1, &buffer);
if (r_create == dmBuffer::RESULT_OK) 
	char* wav_bytes;
	uint32_t wav_size;
	dmBuffer::Result r_get_wav_bytes = dmBuffer::GetBytes(buffer, (void**)&wav_bytes, &wav_size);
	if (r_get_wav_bytes == dmBuffer::RESULT_OK) 
		for(size_t i = 0;i < wav_size;++i)
			wav_bytes[i] = out_bytes[i];
		lua_buffer->m_Buffer = buffer;

I will add to the github. It may not be useful to anyone as an extension, but I think it will help someone as an example.

Thank you for your help!

About the libraries. I think the problem is in the visual studio. I still can’t understand why static libraries write about some kind of info.obj, and dynamic libraries work perfectly. The source is one. I’ll try reinstalling it, hope it helps

1 Like


Project Property->C/C++->Code generation->runtime library->MT
Project Property->Additional->Whole Program Optimization ->No