mike.holler
04/21/2022, 9:51 PMexternal
declarations for the following signatures?
flatbuffers.Builder = function(opt_initial_size) { ... }
flatbuffers.Builder.prototype.clear = function() { ... }
What I have tried is:
@file:JsModule("flatbuffers")
@file:JsNonModule
package flatbuffers
external class Builder(initialSize: Int) {
fun clear()
}
But I get an error:
TypeError: Builder is not a constructor
turansky
04/21/2022, 10:09 PM@JsModule("flatbuffers")
@JsNonModule
external object flatbuffers {
external class Builder(initialSize: Int) {
fun clear()
}
}
Like this?mike.holler
04/21/2022, 10:18 PMpackage flatbuffers
. Wrapper object hasn't helpedmike.holler
04/21/2022, 10:31 PMturansky
04/21/2022, 10:51 PM@JsModule("flatbuffers")
@JsNonModule
external object flatbuffers {
class Builder(initialSize: Int) {
fun clear()
}
}
Works for me 🙂turansky
04/21/2022, 10:53 PM@JsModule
isn’t fine 😞mike.holler
04/21/2022, 10:55 PMturansky
04/21/2022, 10:59 PMmike.holler
04/21/2022, 11:11 PMBig Chungus
04/22/2022, 10:18 AM@JsModule("flatbuffers")
@JsNonModule
external object flatbuffers {
external object Builder {
fun clear()
operator fun invoke(initialSize: Int)
}
}
mike.holler
04/22/2022, 2:10 PMmike.holler
04/22/2022, 2:13 PMTypeError: Cannot read properties of undefined (reading 'invoke')
mike.holler
04/22/2022, 2:13 PMBig Chungus
04/22/2022, 3:55 PM{
flatbuffers: {
SIZEOF_SHORT: 2,
SIZEOF_INT: 4,
FILE_IDENTIFIER_LENGTH: 4,
Encoding: { UTF8_BYTES: 1, UTF16_STRING: 2 },
int32: Int32Array(2) [ 0, 0 ],
float32: Float32Array(2) [ 0, 0 ],
float64: Float64Array(1) [ 0 ],
isLittleEndian: true,
Long: [Function (anonymous)] {
create: [Function (anonymous)],
ZERO: [Object]
},
Builder: [Function (anonymous)] { growByteBuffer: [Function (anonymous)] },
ByteBuffer: [Function (anonymous)] { allocate: [Function (anonymous)] }
}
}
Notice how flatbuffer
module exports an object with a single field also called flatbuffer
. The value of the field is another object which contains your Builder
class. With all that in mind, here's the working wrapper to reflect it:
@JsModule("flatbuffers")
@JsNonModule
external object flatbuffers {
object flatbuffers {
class Builder(opt_initial_size:Int = definedExternally) {
fun clear()
}
}
}
Big Chungus
04/22/2022, 3:56 PM@file:JsModule("flatbuffers")
@file:JsNonModule
@JsName("flatbuffers")
external object FlatBuffers {
class Builder(opt_initial_size:Int = definedExternally) {
fun clear()
}
}
Big Chungus
04/22/2022, 3:57 PMmike.holler
04/22/2022, 3:58 PMmike.holler
04/22/2022, 3:59 PMBig Chungus
04/22/2022, 3:59 PMconsole.log
is a godsend for these kind of things. Just be sure not to use println
instead as that calls Any::toString
before printing, which in most cases will just return [object Object]
mike.holler
04/22/2022, 4:00 PMprintln
Big Chungus
04/22/2022, 4:01 PMprintln == console.log
in Kotlin/JS 😄mike.holler
04/22/2022, 4:02 PMmike.holler
04/22/2022, 4:02 PMturansky
04/22/2022, 6:05 PM@file:JsModule("flatbuffers")
@file:JsNonModule
@file:JsQualifier("flatbuffers")
package flatbuffers
external class Builder(
opt_initial_size:Int = definedExternally,
) {
fun clear()
}
Without redundand object
?