Jump to content

Compile lua file api


DBY

Recommended Posts

Posted

I want to compile a file using API mta. But there are two functions that do not exist in MTA (fileSave and fileLoad)

Any ideas?

https://luac.multitheftauto.com/api/

local FROM="example.lua" 
local TO="compiled.lua" 
fetchRemote( "https://luac.multitheftauto.com/?compile=1&debug=0&obfuscate=0", function(data) fileSave(TO,data) end, fileLoad(FROM), true ) 

Posted

You can write it...

function fileSave( File, Data ) 
    if( fileExists( File ) ) then 
        fileDelete( File ); 
    end 
  
    local File = fileCreate( File ); 
    fileWrite( File, Data ); 
    fileClose( File ); 
end 
  
function fileLoad( File ) 
    return fileRead( File, fileGetSize( File ) ); 
end 

Posted
You can write it...
function fileSave( File, Data ) 
    if( fileExists( File ) ) then 
        fileDelete( File ); 
    end 
  
    local File = fileCreate( File ); 
    fileWrite( File, Data ); 
    fileClose( File ); 
end 
  
function fileLoad( File ) 
    return fileRead( File, fileGetSize( File ) ); 
end 

That I had already tried, but still not working. (Now do not get errors in the debugscript)

Posted

Try

function fileSave( sFile, sData ) 
    if fileExists( sFile ) then 
        fileDelete( sFile ); 
    end 
  
    local pFile = fileCreate( sFile ); 
    fileWrite( pFile, sData ); 
    fileClose( pFile ); 
end 
  
function fileLoad( sFile ) 
    local pFile = fileOpen( sFile, true ); 
    
    local sData = fileRead( pFile, fileGetSize( pFile ) ); 
     
    fileClose( pFile ); 
     
    return sData; 
end 

Posted
Try
function fileSave( sFile, sData ) 
    if fileExists( sFile ) then 
        fileDelete( sFile ); 
    end 
  
    local pFile = fileCreate( sFile ); 
    fileWrite( pFile, sData ); 
    fileClose( pFile ); 
end 
  
function fileLoad( sFile ) 
    local pFile = fileOpen( sFile, true ); 
    
    local sData = fileRead( pFile, fileGetSize( pFile ) ); 
     
    fileClose( pFile ); 
     
    return sData; 
end 

Thank you very much for commenting, but these functions do the same thing that I've done.

PS: Still not working.

Posted
function fileSave(filePath, fileContent) 
    if fileExists(filePath) then 
        fileDelete(filePath) 
    end 
    local file = fileCreate(filePath) 
    fileWrite(file, fileContent) 
    fileClose(file) 
end 
  
function fileLoad(filePath) 
    if fileExists(filePath) then 
        local file = fileOpen(filePath) 
        local fileContent = fileRead(file, fileGetSize(file)) 
        fileClose(file) 
        return fileContent 
    end 
end 
  
function fileCompile(FROM, TO) 
    if FROM and TO then 
            fetchRemote("https://luac.multitheftauto.com/?compile=1&debug=0&obfuscate=0", function(data) fileSave(TO, data) end, fileLoad(FROM), true) 
    end 
end 

The problem now is that it creates the file but the page returns "ERROR"

Posted

Works for me:

function fileSave( sFile, sData ) 
    if fileExists( sFile ) then 
        fileDelete( sFile ); 
    end 
  
    local pFile = fileCreate( sFile ); 
    fileWrite( pFile, sData ); 
    fileClose( pFile ); 
end 
  
function fileLoad( sFile ) 
    local pFile = fileOpen( sFile, true ); 
    
    local sData = fileRead( pFile, fileGetSize( pFile ) ); 
    
    fileClose( pFile ); 
    
    return sData; 
end 
  
  
local FROM="example.lua" 
local TO="compiled.luac" 
fetchRemote( "https://luac.multitheftauto.com/?compile=1&debug=0&obfuscate=0",  
    function(data) 
        print( tostring( data ) ) 
        fileSave( TO, data )  
    end, fileLoad( FROM ), true ); 

Posted
The problem now is that it creates the file but the page returns "ERROR"

The page on a web browser displays "ERROR" when the uploaded file has a syntax error.

Posted
The problem now is that it creates the file but the page returns "ERROR"

The page on a web browser displays "ERROR" when the uploaded file has a syntax error.

Or fileLoad or codification doesnt work

Posted

No, the file functions he is using return bools, file handlers or an integer representing a number of bytes either read or written. The only way "ERROR" could be returned is through fetchRemote.

Posted

tumblr_mkiylvrDGJ1qbkjb0o1_500.gif

function fileLoad(path) 
    local File = fileOpen(path, true) 
    if File then 
        local data = fileRead(File, fileGetSize(File)) 
        fileClose(File) 
        return data 
    end 
end 
  
function fileSave(path, data) 
    local File = fileCreate(path) 
    if File then 
        fileWrite(File, data) 
        fileClose(File) 
    end 
end 

Posted
function fileLoad(path) 
    local File = fileOpen(path, true) 
    if File then 
        local data = fileRead(File, fileGetSize(File)) 
        fileClose(File) 
        return data 
    end 
end 
  
function fileSave(path, data) 
    local File = fileCreate(path) 
    if File then 
        fileWrite(File, data) 
        fileClose(File) 
    end 
end 

Your code does the same job as my code. Still creates a file containing "ERROR".

Posted

If it throws an error when you try to compile the script on the website, then you have a syntax error in your script. It works fine for me and it throws "ERROR" when I try to compile a file with a syntax error.

Posted
If it throws an error when you try to compile the script on the website, then you have a syntax error in your script. It works fine for me and it throws "ERROR" when I try to compile a file with a syntax error.

I put "print()" into file i want compile. But still return "error"

Posted

Apparently, the problem is not the script, it's my localhost. FetchRemote not work, I tried some compilers and none worked for me.

Your comments are appreciated.

Posted
Apparently, the problem is not the script, it's my localhost. FetchRemote not work, I tried some compilers and none worked for me.

Your comments are appreciated.

Lel, the test funct from getResourceScripts works perfectly for compiling ;)

Just modify the funct.

Add xmlUnloadFile for meta xmlFile (or will keep opening files and stay loaded at memory).

  • 1 month later...
Posted

Because you need to do port forwarding. Execute "openports" in your server console and it will you whether your ports are open or no. If no then do port forwarding.

Posted (edited)
Because you need to do port forwarding. Execute "openports" in your server console and it will you whether your ports are open or no. If no then do port forwarding.

Port forwarding (in regards to /openports) is for incoming connections, not outgoing. The API server already has the necessary ports open, and therefore connection should work (unless there's firewall the outgoing server)

Edited by Guest
Posted
Because you need to do port forwarding. Execute "openports" in your server console and it will you whether your ports are open or no. If no then do port forwarding.

Port forwarding is for incoming connections, not outgoing. The API server already has the necessary ports open, and therefore connection should work (unless there's firewall the outgoing server)

I wonder why callRemote was not working for me when my ports were not open? Hmmm I think it was an year ago.

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