- let do_func pkg (fn, f, l) =
- printf "\nstatic int luaM_%s_%s(lua_State *L)\n{\n" pkg.name fn.fname;
- let i = ref 0 in
- List.iter (function ((const, typ), name) ->
- incr i;
+ let do_func ob pkg (fn, f, l) =
+ (* return inline function *)
+ fprintf ob "\nstatic int luaM_ret_%s_%s(lua_State *L" pkg.name fn.fname;
+ let retlen = List.fold_left (fun i t ->
+ let i = i + 1 in
+ match t with
+ | true, typ -> fprintf ob ", const %s luaM_x%d" (t1 typ.ctype) i; i
+ | false, typ -> fprintf ob ", %s luaM_x%d" (t1 typ.ctype) i; i
+ ) 0 fn.rettype in
+ fprintf ob ")\n{\n";
+ ignore (List.fold_left (fun i (const, typ) ->
+ let i = i + 1 in
+ let (p, f, l) = typ.push in
+ put_line ob l f;
+ fprintf ob " %s;\n" (tplize p (sprintf "luaM_x%d" i));
+ if not const then (
+ match typ.dtor with
+ | None -> ()
+ | Some(dtor, f, l) ->
+ put_line ob l f;
+ fprintf ob " %s;\n" (tplize dtor (sprintf "&luaM_x%d" i))
+ ); i
+ ) 0 fn.rettype) ;
+ fprintf ob " return %d;\n}\n" retlen;
+
+ (* main function *)
+ fprintf ob "\nstatic int luaM_%s_%s(lua_State *L)\n{\n" pkg.name fn.fname;
+ ignore (List.fold_left (fun i ((const, typ), name) ->
+ let i = i + 1 in