Jump to content

Rewrite/Export Functions


SuperBrandy

Recommended Posts

Hey there!

I am searching a solution for a function export problem. What i want to do is:

- replace functions with a script( that will work for all the code in the same script)

- the replaced functions should be accessible for other resources

Example:

- resource A replaces outputChatBox() so every text called with this will be green

- resource B contains the outputChatBox() and the text created there should automatically be green without IMPORTING anything

Hopefully there are some smarter guys out there, thanks for your help!

Link to comment

I'm pretty sure you can't replace exported functions without editing meta AND restarting the required resource. But you can always do that somewhere outside of that resource. Though you can make predefined exported functions and replace these functions in other resources so they call that resource.

If you don't really need exports to get function results, you can simply use events + replaced functions in another resource. A replaced resource should look something like:

function outputChatBox(text,player) 
  return triggerEvent("outputChatBoxEvent",player,text,player) 
end 

That should be more flexible.

If you really need replacements with dynamc exports and stuff, this should require MTA codebase changes.

Link to comment
  • MTA Team

Edit: You could also copy the "util" code to each resource but you would have to maintain the code in each resource.

Resource A: (e.g. called util)

This resource only serves the code by calling its exported function.

  
<meta> 
    <script src="script.lua"/> 
    <export function="getCode"/> 
</meta> 

LUACODE = [===[ 
    local _outputChatBox = outputChatBox 
    function outputChatBox(message, target, _, _, _, colorcoded) 
        return _outputChatBox(message, target, 0, 255, 0, colorcoded) 
    end 
]===] 
  
function getCode() 
    return LUACODE 
end 

Resource B

This resource has to load the code from util on start.

  
<meta> 
    <include resource="util"/> 
    <script src="script.lua"/> 
</meta> 

loadstring(exports.util:getCode())() 
  

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...