 +	{ lua_pushcfunction(L, f); lua_pushstring(L, s); lua_call(L, 1, 0); }
 +#define l_setconst(c, s) \
 +	{ lua_pushnumber(L, c); lua_setfield(L, LUA_GLOBALSINDEX, s); }
-+#define SS(m, l) Platform::SendScintilla(wid, m, style_num, l)
++#define SSS(m, l) SS(sci, m, style_num, l)
 +
 +class LexerLPeg : public ILexer {
 +	lua_State *L;
 +	PropSetSimple props;
-+	WindowID wid;
++	SciFnDirect SS;
++	sptr_t sci;
 +	bool reinit;
 +	bool multilang;
 +private:
 +	bool Init() {
++    if (sci == 0) return false; // set sci first
++
 +		char p1[50], p2[FILENAME_MAX], p3[FILENAME_MAX], p4[FILENAME_MAX];
 +		props.GetExpanded("lexer.name", p1);
 +		props.GetExpanded("lexer.lua.home", p2);

+		lua_getfield(L, -1, "fold");
+		if (lua_isfunction(L, -1)) {
+			int currentLine = styler.GetLine(startPos);
+			long p = Platform::SendScintilla(wid, SCI_GETCHARACTERPOINTER);
+			lua_pushlstring(L, reinterpret_cast<char *>(p) + startPos, lengthDoc);
+			lua_pushnumber(L, startPos);
+			lua_pushnumber(L, currentLine);

 
diff -r ffde119d297e src/ScintillaBase.cxx
--- scintilla/src/ScintillaBase.cxx	Wed Jul 28 17:54:24 2010 +1000
+++ scintilla/src/ScintillaBase.cxx	Fri Aug 20 22:26:52 2010 -0400
@@ -517,7 +517,12 @@
 	if (!pdoc->pli) {
 		pdoc->pli = new LexState(pdoc);
 	}
-	return static_cast<LexState *>(pdoc->pli);
+	// modified by Mitchell
+	LexState *state = static_cast<LexState *>(pdoc->pli);
+	state->PrivateCall(SCI_GETDIRECTFUNCTION, reinterpret_cast<void *>(WndProc(SCI_GETDIRECTFUNCTION, 0, 0)));
+	state->PrivateCall(SCI_SETDOCPOINTER, reinterpret_cast<void *>(WndProc(SCI_GETDIRECTPOINTER, 0, 0)));
+	return state;
+	// end modified by Mitchell
 }
 
 void LexState::SetLexerModule(const LexerModule *lex) {
@@ -534,7 +539,7 @@
 }
 
 void LexState::SetLexer(uptr_t wParam) {
-	lexLanguage = wParam;
+	lexLanguage = SCLEX_LPEG; // modified by Mitchell
 	if (lexLanguage == SCLEX_CONTAINER) {
 		SetLexerModule(0);
 	} else {
@@ -546,12 +551,13 @@
 }
 
 void LexState::SetLexerLanguage(const char *languageName) {
