-
Notifications
You must be signed in to change notification settings - Fork 92
Description
Hello,
for the last 2 days I've been trying to figure out how I can use custom C++ library from within Lua and stumbled upon this wrapper, which looks like it does what I need it to do.
So I have this basic library with 1 class:
#pragma once
#include <string>
using namespace std;
class myClass
{
private:
int num;
string str;
public:
myClass(int, string);
void setInt(int);
void setString(string);
int getInt() { return num; }
string getString() { return str; }
};#include "Header.h"
myClass::myClass(int i, string str) : num(i), str(str)
{ }
void myClass::setInt(int i)
{ this->num = i; }
void myClass::setString(string str)
{ this->str = str; }I obviously use it in C++ like this
#include <iostream>
#include <Header.h>
using namespace std;
int main()
{
myClass mc(3, "hello");
cout << mc.getInt() << endl << mc.getString() << endl;
mc.setInt(5);
mc.setString("world");
cout << mc.getInt() << endl << mc.getString() << endl;
return 0;
}is there any way (and if so, how?) to use it from within Lua in a similar way? like this:
local cl = myClass(3, "hello");
print(cl.getInt(), cl.getString());
cl.setInt(5);
cl.setString("world");
print(cl.getInt(), cl.getString());Does the library has to be compiled as a static, or dynamic library?
Do I only include the wrapper and Link the class as shown in the readme?
How does the Lua find the linked library then? With C++ I have to link it while compiling, providing a path to the lib. How does this work with Lua?
I'm sorry if this is stupid question, but I've used Lua only for game scripting so far, never really used it with binding to any language, therefore I have no idea how to work with the wrapper provided. Any help is highly appreciated!