jprbest
jprbest

Reputation: 737

How to get the global path where lua is installed

I'm writing a lua application that will contain a relative path, where no matter where lua is installed it will copy a file to clibs folder for example

getPath = getWhereLuaInstalled (could be C:\program file(x86)\lua\5.1 or c:\lua\5.1..)

Using the package.path will return for me all the path lua will search to find the executable. Any Idea?

Thanks

Upvotes: 1

Views: 2079

Answers (2)

kikito
kikito

Reputation: 52698

Normally you just use a dot for that ("."). You can add relative paths to it: ./my/relative/path

Upvotes: 1

Moop
Moop

Reputation: 3611

It looks like you are designing this for a windows machine (.dll and your example paths indicate this) so this is a possible solution.

local io = require "io" 

function getWhereLuaInstalled() 
  local handle = io.popen('where lua')
  local path = handle:read('*a'):match("(.*\\)")
  handle:close()
  return path
end

This can easily be modified for linux systems by replacing where lua with which lua.

Upvotes: 2

Related Questions