private static CharPtr generic_reader(lua_State L, object ud, out uint size) { CharPtr s; Readstat stat = (Readstat)ud; luaL_checkstack(L, 2, "too many nested functions"); lua_pushvalue(L, stat.f); /* get function */ lua_call(L, 0, 1); /* call it */ if (lua_isnil(L, -1)) { size = 0; return(null); } else if ((s = lua_tostring(L, -1)) != null) { if (stat.mode != null) /* first time? */ { s = checkrights(L, stat.mode, s); /* check mode */ stat.mode = null; /* to avoid further checks */ if (s != null) { luaL_error(L, s); } } lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */ return(lua_tolstring(L, RESERVEDSLOT, out size)); } else { luaL_error(L, "reader function must return a string"); size = 0; //FIXME:added return(null); /* to avoid warnings */ } }
private static int luaB_load_aux(lua_State L, int farg) { int status; Readstat stat = new Readstat(); uint l; CharPtr s = lua_tolstring(L, farg, out l); CharPtr mode = luaL_optstring(L, farg + 2, "bt"); if (s != null) /* loading a string? */ { CharPtr chunkname = luaL_optstring(L, farg + 1, s); status = ((checkrights(L, mode, s) != null) || luaL_loadbuffer(L, s, l, chunkname) != 0) ? 1 : 0; } else /* loading from a reader function */ { CharPtr chunkname = luaL_optstring(L, farg + 1, "=(load)"); luaL_checktype(L, farg, LUA_TFUNCTION); stat.f = farg; lua_settop(L, RESERVEDSLOT); /* create reserved slot */ status = lua_load(L, generic_reader, stat, chunkname); //FIXME:??? } return(load_aux(L, status)); }