Categories > Coding > Lua >

[ Help ] Need help on how to make a API using Lua


SkieHackerYT

Panda Development Team

Posts: 362

Threads: 82

Joined: Apr, 2019

Reputation: 31

  • 0

Posted

is it possible to make a API on lua like example

 

function hello()

    return 'hello world'

 

 

local a = loadstring(readfile(''hello world.lua''))();

print(a:Hellow());

 

Sorry if I wrote like that, buts kinda similar to UI Libraries

 

https://media.discordapp.net/attachments/996322272547704845/1016492646820233246/standard.gif

Murz

Chance

Posts: 112

Threads: 3

Joined: Jul, 2021

Reputation: 16

  • 0

Replied

I feel like this should be possible i dont see why not lol

if i remember correctly you make a table or something and add a function to that table by doing like

 

local table = {}

 

function table:hello()

       return "hello world"

end

 

then just call it like you did and it should work

https://cdn.discordapp.com/attachments/1022610733520912436/1022957841214083214/sigg2.png

 

Ty for rep: Swiney, Byoke, Lion, Locust, Waves, Weeb, Nickk, darkn, Atari, CubeFaces, Lux14, Rice

RealNickk

no longer active

vip

Posts: 3964

Threads: 177

Joined: Feb, 2020

Reputation: 56

  • 0

Replied

@Murz you didnt use "self" so using a colon method is useless and slower than a "." method

Cyros

?Che & Firefox

Posts: 763

Threads: 31

Joined: Feb, 2021

Reputation: 13

  • 0

Replied

cursed code alert!

technically left wrd

haha idrc about this

Murz

Chance

Posts: 112

Threads: 3

Joined: Jul, 2021

Reputation: 16

  • 0

Replied

@RealNickk youre gonna make me cry nickk

https://cdn.discordapp.com/attachments/1022610733520912436/1022957841214083214/sigg2.png

 

Ty for rep: Swiney, Byoke, Lion, Locust, Waves, Weeb, Nickk, darkn, Atari, CubeFaces, Lux14, Rice

RealNickk

no longer active

vip

Posts: 3964

Threads: 177

Joined: Feb, 2020

Reputation: 56

  • 1

Replied

My through explanation of object oriented programming in Lua.

 

Since I'm lazy and would rather not do trigonometry at school, I'll show you how I implement libraries.

 

Object-oriented:

local lib = {}
function lib.new()
    local self = {}

    -- initialize crap in self
    self.Thing = "Hello, world!"

    return setmetatable(self, { __index = lib })
end

function lib.staticFunc()
    return "Hello, world!"
end

function lib:Func() -- do this only when you want this function to be called from the object, and do NOT call dynamic functions like this with the library, only objects (which the reference to the object will be "self" variable in this func)
    return self.Thing
end

return lib

-- callee
local lib = require(some.path.to.lib)
local obj = lib.new() -- makes a separate object that implements lib, can be called many times to make multiple objects

print(lib.staticFunc())
print(obj:Func())

Never call a colon method on the library, only on objects. Same for the static functions, even though it doesn't matter in that context, don't be tempted. It makes your code look unorganized.


Static:

local lib = {}

function lib.func()
    -- do stuff, using lib will refer to the lib table as an upvalue, i do not recommend modifying it
    return "Hello, world!"
end

return lib

-- callee
local lib = require(some.script)
print(lib.func())

There is ZERO reason to use a colon method in this case. Using colon methods here will make your code slower by adding multiple unnecessary opcodes and objects to the stack. Practice good coding habits.

aeon

Owner of Voyager

Posts: 198

Threads: 14

Joined: Sep, 2022

Reputation: 11

  • 0

Replied

oh thats very simple. i am export cader a t loa

local workspace.baseplate = baseplate 
local usercode=- C# && C++

using jjsploitapildllofficiallegit;

throw new NonImplementedException();

localplayer.LoadCoolrealjjsploithaxnolageditionv57

https://media.discordapp.net/attachments/1031726386387365989/1043684000046264390/Frame_2.png  discord.gg/Voyager

Voyager Site 



Users viewing this thread:


( Members: 0, Guests: 1, Total: 1 )