Jump to content

How to export OOP function?


Neproify

Recommended Posts

Posted

Hello. I have code like that:

  
function Player:show(text) 
    triggerClientEvent(self, "notifications:show", root, text) 
end 
  

How to export it?

<export function="Player:show" type="server" /> 

or

<export function="show" type="server" /> 

Sorry for my english. I am from Poland.

Posted
"OOP Syntax

Method: resource:call(...)"

This is about calling the function. Exports are OOP styled but exported function cannot.

The OOP syntax is for the following usage:

getResourceFromName("resource"):call("exportedFunction", 1, "2", "three") 
--or 
Resource.getFromName("resource"):call("exportedFunction", 1, "2", "three") 
--instead of 
call(getResourceFromName("resource"), "exportedFunction", 1, "2", "three") 

Previously known as MrTasty.

Posted

There is not possible to export OOP functions(methods), but you can run the class in other resources.

 local oop_exemple = [[a = {} 
a.__index = a 
  
function a:new() 
    local o = {name = 'test'} 
    setmetatable(o, a) 
    return o 
end 
  
function a:getName() 
    return self.name 
end]] 
  
function getTable() 
    return oop_exemple 
end 

  
loadstring(exports.resource_name:getTable()) () ---- to load the class 
  
local x = a:new() 
print(x:getName()) 
  

  • Like 1

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...