Server-side function exports

So far we have function exporting feature for client-side scripts. This is very useful thing, that lets you to call exported functions across different resources.

My suggestion is to make this feature also available for server-side functions/scripts as well.

What’s the benefit of this feature, you may ask? Well, suppose we have some function called splitstring(), that splits the given string with the specified separator symbol and returns a table of separated strings. Right now we have to include its source in every resource where this function needs to be used, which is not nice. If you need to make changes in the function logic, you have to apply this changes in every copy of this function.

With the “exports” feature we can simply create one resource, called something like utils and put splitstring() function in this resource. Then we export this function with the appropriate signature in the __resource.lua and now we can just call this function from any resource with the following:

exports[“utils”].splitstring(someString, someSeparator)

In conclusion:

  1. No need to copy function source across resources.
  2. Simple function calling through exports table.
  3. Simple code modifying: no need to worry about making changes in the calling function, as it is located only in one place.