LuaPosix: Difference between revisions

From Alpine Linux
Line 96: Line 96:
<span style="color:red">(not working)</span>
<span style="color:red">(not working)</span>
I maybe running it wrong from interactive lua. But it always exits the interactive session.
I maybe running it wrong from interactive lua. But it always exits the interactive session.
'''INPUT'''
'''INPUT'''
*PATH-Location of binary
*PATH-Location of binary

Revision as of 18:38, 9 November 2007

Lua Posix

This is a list of the Lua Posix functions. Included is helpful snipets of code. Install lua posix. To get this list do:

bar = require "posix"
for a in pairs(bar) do print(a) end

access

INPUT

  • Path- file or directory path that wants to be checked
  • Permission - what permissions do you want to check
    • "r" = read
    • "w" = write
    • "x" = execute
    • "f" = all permissions? not sure

OUPUT

  • string - 0 for success, nil for failure if done
bar = require "posix"
temp = bar.access("/etc/passwd", "w")
print(temp)

Will give more information like

bar = require "posix"
print(bar.access("/etc/passwd", "w"))
--If nil will give back the error too
nil     /etc/passwd: Permission denied  13

chdir

INPUT

  • Path - where do you want to change directory to

OUPUT

  • 0 if success
    • nil if failed
bar = require "posix"
bar.chdir("/etc/")
--print(bar.getcwd()) to see where you are

0 if success, nil if failure. If you

print(bar.chdir("/var/lob"))
-- it will print the system error message also
nil     /var/lob: No such file or directory     2

chmod

INPUT

  • PATH - where is the file or directory
    • MODE - what mode to you want to change on the file

OUPUT

  • string - 0 if sucess, nil failure
bar = require "posix"
bar.chmod("/etc/passwd", "a=rwx")
--looks like you need to use the ugoa format for this, not numbers

chown

INPUT

  • Path-location of file or directory
  • UID - User id number
  • GID - Group id number

OUPUT

  • String - 0 is success and nil for failure
bar = require "posix"
print(bar.chown("/etc/passwd",100,200)
--above will give back nil. Since we printed it will also give back the system errors.

ctermid

INPUT

  • NONE- DISPLAYS the terminal id

OUTPUT

  • String with the terminal id
bar = require "posix"
print(bar.ctermid())

dir

Directory listing INPUT

  • PATH - directory

OUTPUT

  • TABLE - table with the file name contents of the directory
    • Failure returns a nil value
bar = require "posix"
bobo = bar.dir("/var/log")
for a,b in ipairs(bobo) do print(b) end
-- the bobo table will output all the file names in /var/log/

errno

Display the error information

INPUT

  • NONE

OUPUT

  • Success, or Error message
bar = require "posix"
a,b = bar.dir("/var/foo"), bar.errno()
print(a,b)
-- a will be nil or 0, b will be No such file or directory or Success

exec

(not working) I maybe running it wrong from interactive lua. But it always exits the interactive session.

INPUT

  • PATH-Location of binary
  • ARGs-options to pass to binary

OUPUT

  • Strings
bar = require "posix"
bobo = bar.exec("/bin/ls", "-l", "/etc/")

files

(not working) Is only returning a function INPUT

  • PATH- Directory

OUPUT

  • 0
  • nil
bar = require "posix"
bobo = bar.files("/etc/bogus/")
print(bobo)

==fork==(needs more explaining) INPUT

  • None

OUPUT If you run this in interactive lua the function will give you a prompt with one more >

> >
bar = require "posix"
bar.fork()
for a=1,10 do print(a) end
--the above runs and then exists the fork

getcwd

getenv

getgroup

getlogin

getpassword

getprocessid

kill

link

mkdir

mkfifo

patchconf

putenv

readlink

rmdir

setgid

setuid

sleep

stat

symlink

sysconf

times

ttyname

umask

uname

utime

wait


If you are using this under linux also get

setenv

unsetenv