Skip to content

Instantly share code, notes, and snippets.

View yukurt's full-sized avatar

Kurt Yu yukurt

View GitHub Profile
@yukurt
yukurt / output.txt
Created June 15, 2017 07:08
output.txt
% ./test.lua
101
202
x=101, y=202
number
number
function
/***** struct metatable *****/
.type Point
__gc function: 0x7fced2eaf0a1
@yukurt
yukurt / test.lua
Created June 15, 2017 06:48
test.lua
#!/usr/bin/lua
package.loadlib('./example.so', 'luaopen_example')()
A = example.Point()
A.x = 101
A.y = 202
print(A.x)
print(A.y)
A:greet()
print(swig_type(A.x))
@yukurt
yukurt / example.cpp
Created June 15, 2017 06:44
example.cpp
#include "example.hpp"
#include <cstdio>
void Point::greet()
{
printf("x=%d, y=%d\n", x, y);
}
@yukurt
yukurt / example.hpp
Created June 15, 2017 06:43
example.hpp
struct Point
{
int x;
int y;
void greet();
};
@yukurt
yukurt / test.lua
Created June 15, 2017 06:29
test.lua
#!/usr/bin/lua
package.loadlib('./example.so', 'luaopen_example')()
A = example.MyClass(6, 7)
A:greet()
@yukurt
yukurt / example.cpp
Created June 15, 2017 06:24
example.cpp
#include <example.hpp>
#include <ctime>
#include <cstdio>
MyClass::MyClass(int a, int b): x(a), y(b) {}
void MyClass::greet()
{
printf("Hello, world: x=%d y=%d\n", x, y);
}
@yukurt
yukurt / example.hpp
Created June 15, 2017 06:22
example.hpp
class MyClass
{
public:
MyClass(int a, int b);
void greet();
private:
int x;
int y;
};
@yukurt
yukurt / example.i
Created June 14, 2017 08:50
example.i
%module example
%{
/* Includes the header in the wrapper code */
#include "example.hpp"
%}
/* Parse the header file to generate wrappers */
%include "example.hpp"
@yukurt
yukurt / example.cpp
Created June 14, 2017 08:48
example.cpp
#include <example.hpp>
#include <ctime>
double My_variable = 3.0;
int fact(int n) {
if (n <= 1) return 1;
else return n*fact(n-1);
}
@yukurt
yukurt / example.hpp
Created June 14, 2017 08:46
example.hpp
extern double My_variable;
int fact(int n);
int my_mod(int x, int y);
char *get_time();