Replace deprecated luaL_openlib() by luaL_register()
[apps/madmutt.git] / tools / cpkg2c.mll
index a3a3782..a942ee7 100644 (file)
@@ -496,7 +496,7 @@ and ext_member m f = parse
           fprintf ob "};\n";
 
           (* dump struct init func *)
-          fprintf ob "\nstatic void %s_init(void)\n{\n" pkg.name;
+          fprintf ob "\nstatic void (%s_init)(void)\n{\n" pkg.name;
           List.iter (function (m, _, _) ->
             if not (fst m.typ) then
               let init, f, l = m.init in
@@ -585,7 +585,7 @@ int luaopen_%s(lua_State *L)
     %s_init();
 
     /* create methods table, add it the the table of globals */
-    luaL_openlib(L, \"%s\", luaM_%s_methods, 0);
+    luaL_register(L, \"%s\", luaM_%s_methods);
     methods = lua_gettop(L);
 
     lua_newtable(L);                            /* for new members   */
@@ -621,21 +621,21 @@ int luaopen_%s(lua_State *L)
 (* }}} *)
 
   let usage () =
-    output_string stderr "usage: cpkg2c (-h | -c) file.cpkg -o output\n";
+    output_string stderr "usage: cpkg2c file.cpkg header.out source.out\n";
     exit 1
 
+  let warn ob = output_endline ob "/*** THIS FILE IS AUTOGENERATED !!! ***/"
+
+  let process fn file l =
+    (try Unix.unlink file with _ -> ());
+    let ob = open_out_gen  [ Open_trunc ; Open_wronly; Open_creat ] 0o444 file in
+    warn ob; fn ob l; close_out ob
+
   let _ =
-    let warn ob = output_endline ob "/*** THIS FILE IS AUTOGENERATED !!! ***/" in
-    if Array.length Sys.argv != 5 then usage();
-    let file   = Sys.argv.(2) in
+    if Array.length Sys.argv != 4 then usage();
+    let file   = Sys.argv.(1) in
     let lexbuf = L.from_channel (open_in file) in
     let l      = (startchunk cLine file lexbuf) in
-    if Sys.argv.(3) = "-o" then
-        let ob = open_out_gen [ Open_trunc ; Open_wronly; Open_creat ] 0o444 Sys.argv.(4) in
-        match Sys.argv.(1) with
-        | "-h" -> warn ob; do_h ob l; close_out ob
-        | "-c" -> warn ob; do_c ob l; close_out ob
-        | _    -> usage ()
-    else
-      usage();
+    process do_h Sys.argv.(2) l;
+    process do_c Sys.argv.(3) l
 }