premake5 how to set outdir based on platform + configuration? - premake

I'd like to set the outdir/targetdir for each combination of platform + configuration.
function SetLibTargetDir(platforms, configs)
for i2,c in ipairs(configs) do
for i,p in ipairs(platforms) do
filter ("configurations:" .. c, "platforms:" .. p)
targetdir("bin/" .. p .. "/" .. c)
libdirs ("bin/" .. p .. "/" .. c)
libdirs ("bin_prebuilt/" .. p .. "/" .. c)--manually generated libs/dlls that premake5 can't handle
end
end
end
SetLibTargetDir({"Win32", "Win64"}, {"Debug", "Release", "Final"})
I tried using this code, while it gets the config right(debug/release/final). It places everything in Win64, so the 32 bit files & 64 files all end up in the same directory.
What am I doing wrong here? I'd like each combination of platform + configuration to have its own output dir and library paths.
Thanks

Stumbled across the answer:
https://github.com/premake/premake-core/wiki/Tokens
"%{cfg.buildcfg}" get the config
"%{cfg.platform}" gets the platform
So this code works:
targetdir("bin/" .. "%{cfg.platform}" .. "/" .. "%{cfg.buildcfg}")
libdirs("bin/" .. "%{cfg.platform}" .. "/" .. "%{cfg.buildcfg}")
libdirs("bin_prebuilt/" .. "%{cfg.platform}" .. "/" .. "%{cfg.buildcfg}")

Related

New to API; Trying to get info from API of IQAir but Incorrect API Key in RStudio

I was trying to get the content from an API (with key) from IQAir. The documentation of the API can be found via this link [api documentation][1].
I am using RStudio and new to using API. The code I use is as follow:
myurl <- paste0("http://api.airvisual.com/v2/countries?key=", Sys.getenv("my_key"))
my_raw_result <- httr::GET(myurl)
str(my_raw_result$content)
mycontent <- httr::content(my_raw_result, as = "text")
mycontent.json <- jsonlite::fromJSON(mycontent)
dplyr::glimpse(mycontent.json)
And the screenshot for the documentation is
[documentation screenshot][2]
I got an error message as below:
> dplyr::glimpse(mycontent.json)
List of 2
$ status: chr "fail"
$ data :List of 1
..$ message: chr "incorrect_api_key"
Could someone help with this? Thank you very much!
[1]: https://api-docs.iqair.com/?version=latest
[2]: https://i.stack.imgur.com/cRSiO.png

How to reference a hyperlink by id in a reST text?

I have the following reST text:
See this `example <https://example.org/1>`_ or this `example <https://example.org/2>`_.
But I don't want to use the embedded URI syntax because I found it less readable. What should I do for referencing my links?
See this `???`_ or this `???`_.
.. _exemple1: https://example.org/1
.. _exemple2: https://example.org/2
I have found the response here https://stackoverflow.com/a/40555211/887855
See this `example <exemple1_>`__ or this `example <exemple2_>`__.
.. _exemple1: https://example.org/1
.. _exemple2: https://example.org/2

Syntactical issue between order of two functions

Is there any order to be maintained while placing functions one another?
I just tried the code on the online compiler provided by purescript.org itself
"http://try.purescript.org"
module Main where
import Prelude
import Data.List
import Data.Array ((..))
import Data.Traversable (traverse)
import Control.Monad.Eff.Console(log)
import TryPureScript(render,withConsole)
main = render =<< withConsole do
log $ "Hello world"
traverse (\x -> log $ show $ x) (1..10)
log $ "Hello world"
The code is compiling absolutely fine when the last log function is removed or when the traverse function is removed.But its not working while they are placed in such an order.These two(log & traverse) functions are working perfectly individually but not together.Help me to get out of this issue.
I think the error message already give you a hint, you can fix by
_ <- traverse (\x -> log $ show $ x) (1..10)
-- or
void $ traverse (\x -> log $ show $ x) (1..10)

Internal representation of Haskell Data.Map

How can I view the internal representation of Haskell Data.Map?
Also, what kind of data structure is used to implement it?
Is it essentially a red black tree?
Or some kind of heap min?
Here is a simple example that I am interested in dumping to a text file
(or even better, a Graphviz dot representation).
module Main( main ) where
import qualified Data.Map as Map
t = Map.fromList([
(6,"six"),
(2,"two"),
(8,"eight"),
(3,"three"),
(5,"five")])
main = do
putStrLn $ show $ Map.lookup 3 t
putStrLn $ show $ Map.lookup 7 t
Here is a textual dump with showTreeWith:
module Main( main ) where
import qualified Data.Map as Map
t = Map.fromList([
(6,"six"),
(2,"two"),
(8,"eight"),
(3,"three"),
(5,"five")])
main = do
putStrLn $ Map.showTreeWith (\k x -> show (k,x)) True False t
putStrLn $ show $ Map.lookup 3 t
putStrLn $ show $ Map.lookup 7 t
And here is how it looks:
$ ghc main.hs
$ ./main
(6,"six")
+--(3,"three")
| +--(2,"two")
| +--(5,"five")
+--(8,"eight")
Just "three"
Nothing
According to the documentation for Haskell's Data.Map:
The implementation of Map is based on size balanced binary trees (or trees of bounded balance)

Why Lua+Nginx says it cannot call global function?

I have two simple functions that detects browser and operating system based on user agent and they are stored in file useragent.lua.
function detect_browser_platform(user_agent)
-- Here goes some string matching and similar stuff
return browser_platform
end
function detect_os_platform(user_agent)
-- Here goes some string matching and similar stuff
return os_platform
end
function detect_env_pattern(user_agent)
return detect_operating_system_platform(user_agent) .. "-" .. detect_browser_platform(user_agent) .. "-" .. ngx.var.geoip2_data_country_code
end
In virtual host configuration file, there is a line that says when request looks like /lua execute lua script: /var/www/default/test.lua.
In test.lua I have this code:
local posix = require('posix')
local redis = require('redis')
require('useragent')
-- Some code goes here
local user_agent = ngx.req.get_headers()['User-Agent']
local pattern_string = detect_env_pattern(user_agent)
ngx.say(pattern_string)
ngx.exit(200)
But for some reason when I reload nginx nginx -s reload, this codes works only first time. When I make another request it says this error:
2016/09/19 12:30:08 [error] 19201#0: *125956 lua entry thread aborted: runtime error: /var/www/default/test.lua:199: attempt to call global 'detect_env_pattern' (a nil value)
And I have no idea what is happening here. I have just started programming in Lua and don't have time to go deep with language understandings... So why am I getting this error?
Wrap it by a table:
local M={};
function detect_browser_platform(user_agent)
-- Here goes some string matching and similar stuff
return browser_platform
end
function detect_os_platform(user_agent)
-- Here goes some string matching and similar stuff
return os_platform
end
function detect_env_pattern(user_agent)
return detect_operating_system_platform(user_agent) .. "-" .. detect_browser_platform(user_agent) .. "-" .. ngx.var.geoip2_data_country_code
end
M.detect_env_pattern = detect_env_pattern
return M
in base lua file:
local useragent = require('useragent')
--.....
local user_agent = ngx.req.get_headers()['User-Agent']
local pattern_string = useragent.detect_env_pattern(user_agent)
ngx.say(pattern_string)
ngx.exit(200)

Resources