223 if (getHandle(xpu, ExternalEntityKey) == 0) return 1; /* no handle */ |
225 if (getHandle(xpu, ExternalEntityKey) == 0) return 1; /* no handle */ |
224 child = createlxp(L); |
226 child = createlxp(L); |
225 child->parser = XML_ExternalEntityParserCreate(p, context, NULL); |
227 child->parser = XML_ExternalEntityParserCreate(p, context, NULL); |
226 if (!child->parser) |
228 if (!child->parser) |
227 luaL_error(L, "XML_ParserCreate failed"); |
229 luaL_error(L, "XML_ParserCreate failed"); |
228 lua_getref(L, xpu->tableref); /* child uses the same table of its father */ |
230 lua_rawgeti(L, LUA_REGISTRYINDEX, xpu->tableref); /*lua_getref(L, xpu->tableref); */ /* child uses the same table of its father */ |
229 child->tableref = luaL_ref(L, LUA_REGISTRYINDEX); |
231 child->tableref = luaL_ref(L, LUA_REGISTRYINDEX); |
230 lua_pushstring(L, base); |
232 lua_pushstring(L, base); |
231 lua_pushstring(L, systemId); |
233 lua_pushstring(L, systemId); |
232 lua_pushstring(L, publicId); |
234 lua_pushstring(L, publicId); |
233 docall(xpu, 4, 1); |
235 docall(xpu, 4, 1); |
447 int status; |
449 int status; |
448 xpu->L = L; |
450 xpu->L = L; |
449 xpu->state = XPSok; |
451 xpu->state = XPSok; |
450 xpu->b = &b; |
452 xpu->b = &b; |
451 lua_settop(L, 2); |
453 lua_settop(L, 2); |
452 lua_getref(L, xpu->tableref); /* to be used by handlers */ |
454 lua_rawgeti(L, LUA_REGISTRYINDEX, xpu->tableref); /*lua_getref(L, xpu->tableref);*/ /* to be used by handlers */ |
453 status = XML_Parse(xpu->parser, s, (int)len, s == NULL); |
455 status = XML_Parse(xpu->parser, s, (int)len, s == NULL); |
454 if (xpu->state == XPSstring) dischargestring(xpu); |
456 if (xpu->state == XPSstring) dischargestring(xpu); |
455 if (xpu->state == XPSerror) { /* callback error? */ |
457 if (xpu->state == XPSerror) { /* callback error? */ |
456 lua_rawgeti(L, LUA_REGISTRYINDEX, xpu->tableref); /* get original msg. */ |
458 lua_rawgeti(L, LUA_REGISTRYINDEX, xpu->tableref); /* get original msg. */ |
457 lua_error(L); |
459 lua_error(L); |
515 lxp_userdata *xpu = checkparser(L, 1); |
517 lxp_userdata *xpu = checkparser(L, 1); |
516 lua_pushboolean(L, XML_StopParser(xpu->parser, XML_FALSE) == XML_STATUS_OK); |
518 lua_pushboolean(L, XML_StopParser(xpu->parser, XML_FALSE) == XML_STATUS_OK); |
517 return 1; |
519 return 1; |
518 } |
520 } |
519 |
521 |
520 static const struct luaL_reg lxp_meths[] = { |
522 #if !defined LUA_VERSION_NUM |
|
523 /* Lua 5.0 */ |
|
524 #define luaL_Reg luaL_reg |
|
525 #endif |
|
526 |
|
527 static const struct luaL_Reg lxp_meths[] = { |
521 {"parse", lxp_parse}, |
528 {"parse", lxp_parse}, |
522 {"close", lxp_close}, |
529 {"close", lxp_close}, |
523 {"__gc", parser_gc}, |
530 {"__gc", parser_gc}, |
524 {"pos", lxp_pos}, |
531 {"pos", lxp_pos}, |
525 {"setencoding", lxp_setencoding}, |
532 {"setencoding", lxp_setencoding}, |
528 {"setbase", setbase}, |
535 {"setbase", setbase}, |
529 {"stop", lxp_stop}, |
536 {"stop", lxp_stop}, |
530 {NULL, NULL} |
537 {NULL, NULL} |
531 }; |
538 }; |
532 |
539 |
533 static const struct luaL_reg lxp_funcs[] = { |
540 static const struct luaL_Reg lxp_funcs[] = { |
534 {"new", lxp_make_parser}, |
541 {"new", lxp_make_parser}, |
535 {NULL, NULL} |
542 {NULL, NULL} |
536 }; |
543 }; |
537 |
544 |
538 |
545 |
539 /* |
546 /* |
540 ** Assumes the table is on top of the stack. |
547 ** Assumes the table is on top of the stack. |
541 */ |
548 */ |
542 static void set_info (lua_State *L) { |
549 static void set_info (lua_State *L) { |
543 lua_pushliteral (L, "_COPYRIGHT"); |
550 lua_pushliteral (L, "_COPYRIGHT"); |
544 lua_pushliteral (L, "Copyright (C) 2003-2007 Kepler Project"); |
551 lua_pushliteral (L, "Copyright (C) 2003-2012 Kepler Project"); |
545 lua_settable (L, -3); |
552 lua_settable (L, -3); |
546 lua_pushliteral (L, "_DESCRIPTION"); |
553 lua_pushliteral (L, "_DESCRIPTION"); |
547 lua_pushliteral (L, "LuaExpat is a SAX XML parser based on the Expat library"); |
554 lua_pushliteral (L, "LuaExpat is a SAX XML parser based on the Expat library"); |
548 lua_settable (L, -3); |
555 lua_settable (L, -3); |
549 lua_pushliteral (L, "_VERSION"); |
556 lua_pushliteral (L, "_VERSION"); |
550 lua_pushliteral (L, "LuaExpat 1.2.0"); |
557 lua_pushliteral (L, "LuaExpat 1.3.0"); |
551 lua_settable (L, -3); |
558 lua_settable (L, -3); |
552 } |
559 } |
553 |
560 |
554 |
561 |
|
562 #if !defined LUA_VERSION_NUM || LUA_VERSION_NUM==501 |
|
563 /* |
|
564 ** Adapted from Lua 5.2.0 |
|
565 */ |
|
566 static void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { |
|
567 luaL_checkstack(L, nup, "too many upvalues"); |
|
568 for (; l->name != NULL; l++) { /* fill the table with given functions */ |
|
569 int i; |
|
570 for (i = 0; i < nup; i++) /* copy upvalues to the top */ |
|
571 lua_pushvalue(L, -nup); |
|
572 lua_pushstring(L, l->name); |
|
573 lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ |
|
574 lua_settable(L, -(nup + 3)); |
|
575 } |
|
576 lua_pop(L, nup); /* remove upvalues */ |
|
577 } |
|
578 #endif |
|
579 |
|
580 |
555 int luaopen_lxp (lua_State *L) { |
581 int luaopen_lxp (lua_State *L) { |
556 luaL_newmetatable(L, ParserType); |
582 luaL_newmetatable(L, ParserType); |
557 lua_pushliteral(L, "__index"); |
583 |
558 lua_pushvalue(L, -2); |
584 lua_pushliteral(L, "__index"); |
559 lua_rawset(L, -3); |
585 lua_pushvalue(L, -2); |
560 luaL_openlib (L, NULL, lxp_meths, 0); |
586 lua_rawset(L, -3); |
561 luaL_openlib (L, "lxp", lxp_funcs, 0); |
587 |
562 set_info (L); |
588 luaL_setfuncs (L, lxp_meths, 0); |
563 |
589 lua_pop (L, 1); /* remove metatable */ |
564 return 1; |
590 |
565 } |
591 lua_newtable (L); |
|
592 luaL_setfuncs (L, lxp_funcs, 0); |
|
593 set_info (L); |
|
594 return 1; |
|
595 } |