Git Product home page Git Product logo

clua's Introduction

Clua

Clua is used to register c++ classes and functions in lua.

Example

main.cpp

int main(){
	using namespace std;
	unique_ptr<lua_State, decltype(&lua_close)> lua_state_mgr(luaL_newstate(), lua_close);
	lua_State* state = lua_state_mgr.get();
	luaL_openlibs(state);

	// all variable in global
	CLua clua(state);

	// register c function
	clua.registerCFunction("f1", static_cast<void(*)()>([]()->void {
		ogger::WriteMessage("f1 with no return value and args");
	}));

	// register c++ class
	clua.registerClass<vector<int>>("vector");
	clua.registerCXXConstructorFunction<vector<int>, size_t>("new");

	// register c++ member function
	clua.registerCXXMemberFunction<vector<int>>(
		"pop_back",
		&vector<int>::pop_back
	);

	// register c function as c++ member function
	clua.registerCXXMemberFunction<vector<int>>(
		"push_back", 
		static_cast<void(*)(vector<int>*, int)>([](vector<int>* p, int v) {
			p->push_back(v);
	}));

	// register c++ instance
	vector<int> v;
	v.push_back(2);
	clua.registerCXXInstance("c_vec", &v);

	return luaL_dofile(state, "test.lua");
}

test.lua

f1()
v = vector:new(5)
v:pop_back()
v:push_back(1)
vector.push_back(c_vec, 3)

clua's People

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.