Skip to content

Instantly share code, notes, and snippets.

@awstanley
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awstanley/061765914e55f6a06d4c to your computer and use it in GitHub Desktop.
Save awstanley/061765914e55f6a06d4c to your computer and use it in GitHub Desktop.
--[[-------------------------------------------------------------------
-- Platform detecting Lua initialisation code
-- Copyright (c) 2014 A.W. Stanley <aws@sysfunc.net>
-- Released under the new BSD License
-------------------------------------------------------------------]]--
local lua_dir = "lua"
local lua_init = "lua/server.lua"
-- Pull the first directory
local rpath = package.path:gmatch("([^;]+)(;)")()
rpath = rpath:gsub("\\","/")
rpath = rpath:sub(0,#rpath-9) .. lua_dir .. "/?"
-- Operating system detection
local _, w32count = package.cpath:gsub(".dll",".dll")
if(w32count > 0) then
os.platform = "win32"
os.platform_ext = ".dll"
end
if os.platform == nil then
local _, osxcount = package.cpath:gsub(".dylib",".dylib")
if(osxcount > 0) then
os.platform = "osx"
os.platform_ext = ".dylib"
else
if(osxcount > 0) then
os.platform = "posix"
os.platform_ext = ".so"
end
end
end
package.cpath = package.cpath .. ";" .. rpath .. os.platform_ext
-- Your init call (this is mine)
dofile(lua_init)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment