Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(module_cp).
- -export([rename_module/3,load_module_copy/1]).
- rename_module(Bin, OldName, NewName) ->
- case length(OldName) =/= length(NewName) of
- %% sometimes there are problems if names don't have the same length
- true -> {error,name_lengths_differ};
- false ->
- S = binary_to_list(Bin),
- Tmp = string:replace(S, OldName, NewName),
- RenamedBin = list_to_binary(lists:flatten(Tmp)),
- {ok, RenamedBin}
- end.
- load_module_copy(Mod) ->
- ModName = atom_to_list(Mod),
- {Mod, Bin, _} = code:get_object_code(Mod),
- NewName = case ModName of
- [$x|TL] -> [$y|TL];
- [_|TL] -> [$x|TL]
- end,
- {ok, RenamedBin} = rename_module(Bin, ModName, NewName),
- code:load_binary(list_to_atom(NewName), "", RenamedBin).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement