Jump to content

(lua) alternative to require()


uhm

Recommended Posts

any hack/setting that allows for use of require() in server scripts?

trying to

local client = require "soap.client" 

results in

knipselr.png

also a way to omit the use is also acceptable,

already tried loadstring(the file contents) but that resulted in some error about unknown character near "local"

using nightly, non production envo

edit: also tried loadfile and dofile "alternatives" that basically do the same as require, except they don't try to access c:\windows\ etc

Link to comment

status update:

loadstring seems to do the trick. i just forgot to put quotes around the code. even better works in combo w/ readToEnd from thatfile protection thing

however, follow up question:

local clientx = assert(loadstring("_M = { _COPYRIGHT = 'Copyright (C) 2004-2011 Kepler Project'} return _M"))--readToEnd('soap/luasoapclient.lua') 
  
if clientx ~= nil then 
    outputConsole( "OK") 
    outputConsole( clientx._COPYRIGHT ) 
else 
    outputConsole( "not ok") 
end 

error on line 6: attempt to index local 'clientx' (a function value)

why is this a function? the loadstring oughta return a table with just that _M value?

disregard that i suck cocks

clientx()._COPYRIGHT works

TO CONCLUDE OUR INVESTIGATION; IF UR LOOKIN 4 a lu-alternative to require, use this:

function include (file_name) 
    -- note if theres comments in the file it wont work lolz 
    local file,buffer,toend = fileOpen(file_name),nil,""     
    if (file) then 
        while not fileIsEOF(file) do 
            buffer = fileRead(file,500) 
            toend = toend .. buffer 
        end 
        fileClose(file) 
    end 
    return assert(loadstring(toend)) 
end 
  
-- sample usage 
local mo = include('urmom.lua') 
mo() 
  

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