-
-
Save Minalien/dcb83fc4e74604882029 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass | |
def initialize(val) | |
@my_val = val | |
end | |
def print_val | |
puts "My value is #{@my_val}" | |
end | |
def my_val | |
@my_val | |
end | |
end | |
fun myclass_new(v : Int32) : Void* | |
inst = Pointer(MyClass).malloc(1) | |
inst[0] = MyClass.new v | |
inst as Pointer(Void) | |
end | |
fun myclass_print(instance : Void*) | |
inst = instance as Pointer(MyClass) | |
inst[0].print_val | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local ffi = require("ffi") | |
ffi.cdef[[ | |
void* myclass_new(int val); | |
void myclass_print(void* instance); | |
]] | |
local MyClass = {} | |
MyClass.new = function(val) | |
local inst = {} | |
inst.__native_instance = ffi.C.myclass_new(val) | |
inst.print_val = function(self) | |
ffi.C.myclass_print(self.__native_instance) | |
end | |
return inst | |
end | |
return MyClass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment