Changeset 0be295055302f1118f893a50937072790a2c35bb

Show
Ignore:
Timestamp:
02/09/10 21:27:45 (4 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1265750865 +0000
git-parent:

[9f668ab6b397d4af5b413c24ab76ab6631381144]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1265750865 +0000
Message:

add some more xml helpers

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/modules/lua_noit.c

    r2ea74a7 r0be2950  
    10671067} 
    10681068static int 
     1069noit_lua_xmlnode_name(lua_State *L) { 
     1070  xmlNodePtr *nodeptr; 
     1071  /* the first arg is implicitly self (it's a method) */ 
     1072  nodeptr = lua_touserdata(L, lua_upvalueindex(1)); 
     1073  if(nodeptr != lua_touserdata(L, 1)) 
     1074    luaL_error(L, "must be called as method"); 
     1075  if(lua_gettop(L) == 1) { 
     1076    xmlChar *v; 
     1077    v = (xmlChar *)(*nodeptr)->name; 
     1078    if(v) { 
     1079      lua_pushstring(L, (const char *)v); 
     1080    } 
     1081    else lua_pushnil(L); 
     1082    return 1; 
     1083  } 
     1084  luaL_error(L,"must be called with no arguments"); 
     1085  return 0; 
     1086} 
     1087static int 
    10691088noit_lua_xmlnode_attr(lua_State *L) { 
    10701089  xmlNodePtr *nodeptr; 
     
    10841103    return 1; 
    10851104  } 
    1086   luaL_error(L,"must be called with no arguments"); 
     1105  luaL_error(L,"must be called with one argument"); 
    10871106  return 0; 
    10881107} 
     
    11391158} 
    11401159static int 
     1160noit_lua_xml_docroot(lua_State *L) { 
     1161  int n; 
     1162  xmlDocPtr *docptr; 
     1163  xmlNodePtr *ptr; 
     1164  n = lua_gettop(L); 
     1165  /* the first arg is implicitly self (it's a method) */ 
     1166  docptr = lua_touserdata(L, lua_upvalueindex(1)); 
     1167  if(docptr != lua_touserdata(L, 1)) 
     1168    luaL_error(L, "must be called as method"); 
     1169  if(n != 1) luaL_error(L, "expects no arguments, got %d", n - 1); 
     1170  ptr = lua_newuserdata(L, sizeof(*ptr)); 
     1171  *ptr = xmlDocGetRootElement(*docptr); 
     1172  luaL_getmetatable(L, "noit.xmlnode"); 
     1173  lua_setmetatable(L, -2); 
     1174  return 1; 
     1175} 
     1176static int 
    11411177noit_lua_xpathiter_gc(lua_State *L) { 
    11421178  struct xpath_iter *xpi; 
     
    11831219      } 
    11841220      break; 
     1221    case 'n': 
     1222      if(!strcmp(k,"name")) { 
     1223        lua_pushlightuserdata(L, udata); 
     1224        lua_pushcclosure(L, noit_lua_xmlnode_name, 1); 
     1225        return 1; 
     1226      } 
     1227      break; 
    11851228    default: 
    11861229      break; 
     
    12341277  k = lua_tostring(L, 2); 
    12351278  switch(*k) { 
     1279    case 'r': 
     1280     if(!strcmp(k, "root")) { 
     1281       lua_pushlightuserdata(L, udata); 
     1282       lua_pushcclosure(L, noit_lua_xml_docroot, 1); 
     1283       return 1; 
     1284     } 
     1285     break; 
    12361286    case 'x': 
    12371287     if(!strcmp(k, "xpath")) {