Why we use Lua Binding to C++

C++ 프로그램을 다시 빌드하지 않고도 Lua 스크립트만 수정함으로써 프로그램 수행 흐름을 바꿀 수 있기 때문이다.


Develop Environment Settings

VC++ Project Directory Setting

  • Include Directories: "C:\Program Files (x86)\Lua\5.1\include;" 추가
  • Library Directories: "C:\Program Files (x86)\Lua\5.1\lib;" 추가


Code Snippet

#include <stdio.h>
extern "C" {
	#include <lua.h>
	#include <lualib.h>
	#include <lauxlib.h>
}

void main() {
	lua_State *L = luaL_newstate();
	luaL_openlibs(L);
	if (luaL_dofile(L, "sample.lua")) {
		printf("%s\n", lua_tostring(L, -1));
		lua_pop(L, 1);
	}
	lua_close(L);
}


Video Tutorials

How to embed Lua in your application (Using the Lua C API)

C++과 Lua script연동

(관련 내용은 43 page 부터 시작됨)


References

  1. http://gamedevgeek.com/tutorials/calling-lua-functions/
  2. http://gamedevgeek.com/tutorials/calling-c-functions-from-lua/