Пример #1
0
/*---------------------------------------------------------------------------
	2015/03/02 功能:   
---------------------------------------------------------------------------*/
void LuaLibOpenGL::Initialize(lua_State* A_L)
{
	m_L = A_L;
	luaopen_bit32(A_L);

	FILE* pFile = fopen("OpenGL.lua", "rb");
	if(pFile != NULL)
	{
		fseek(pFile, 0, SEEK_END);
		int nLen = ftell(pFile);
		char* pBuff = new char[nLen + 1];
		pBuff[nLen] = 0;
		fseek(pFile, 0, SEEK_SET);
		fread(pBuff, nLen, 1, pFile);
		fclose(pFile);
		
		luaL_dostring(m_L, pBuff);
		delete[] pBuff;
	}

	// 注册 OpenGL 函数到 gl 表中
	RegistTableGL();

	// 调用初始化函数
	FuncCall("Init");
}
Пример #2
0
 int open_bit32()
 {
     if (L)
     {
         luaopen_bit32(L);
         return 0;
     }
     return -1;
 }
Пример #3
0
interp_t *interp_new(int flags, int ipcfd) {
	interp_t *interp = NULL;
	lua_State *L = NULL;
	static const luaL_Reg ipcfuncs[] = {
		{"ready", bipc_ready},
		{"connect", bipc_connect},
		{NULL, NULL},
	};

	L = luaL_newstate();
	if (L == NULL) {
		return NULL;
	}

	luaopen_base(L);
	luaopen_coroutine(L);
	luaopen_table(L);
	luaopen_string(L);
#if (LUA_VERSION_NUM >= 503)
	luaopen_utf8(L);
#endif
	luaopen_bit32(L);
	luaopen_math(L);
	luaopen_debug(L);
	luaopen_package(L);
	/* not opened: io, os */

	/* create a userdata object that represents the interpreter */
	interp = (interp_t*)lua_newuserdata(L, sizeof(interp_t));
	if (interp == NULL) {
		lua_close(L);
		return NULL;
	}

	memset(interp, 0, sizeof(interp_t));
	interp->ipcfd = ipcfd;
	interp->L = L;

	/* Build a metatable with the methods for our userdata object.
	 * Assign the userdata object to BIRK_IPCNAME */
	luaL_newmetatable(L, BIRK_IPCNAME);
	lua_pushvalue(L, -1);
	lua_setfield(L, -2, "__index");
	luaL_setfuncs(L, ipcfuncs, 0);
	lua_setmetatable(L, -2);
	lua_setglobal(L, BIRK_IPCNAME);

	if ((flags & INTERPF_LOADBIRK) && interp_load(interp, "birk") != BIRK_OK) {
		/* error message is set, caller should check it on return */
		return interp;
	}

	return interp;
}
Пример #4
0
void LuaInterface::createLuaState()
{
    // creates lua state
    L = luaL_newstate();
    if(!L)
        g_logger.fatal("Unable to create lua state");

    // load lua standard libraries
    luaL_openlibs(L);

    // load bit32 lib for bitwise operations
    luaopen_bit32(L);

    // creates weak table
    newTable();
    newTable();
    pushString("v");
    setField("__mode");
    setMetatable();
    m_weakTableRef = ref();

    // installs script loader
    getGlobal("package");
    getField("loaders");
    pushCFunction(&LuaInterface::luaScriptLoader);
    rawSeti(5);
    pop(2);

    // replace dofile
    pushCFunction(&LuaInterface::lua_dofile);
    setGlobal("dofile");

    // dofiles
    pushCFunction(&LuaInterface::lua_dofiles);
    setGlobal("dofiles");

    // replace loadfile
    pushCFunction(&LuaInterface::lua_loadfile);
    setGlobal("loadfile");
}
Пример #5
0
bool LuaWrapper::openBit32()		{ luaopen_bit32(m_luaState);		return true; }