Results 1 to 9 of 9

Thread: Allow JSON file read/load

  1. #1
    Basic Member
    Join Date
    Dec 2016
    Posts
    707

    Question Allow JSON file read/load

    Is it possible to load a pure JSON file through the dofile(), require() or even by leveraging the provided dkjson.lua module?

    In my web-server bot implementation I'm trying to organize my code better and thus created pure JSON file for various data that I want re-used both on the bot-running instance as well as the back-end server.

    For example, I created a web_config.json file that is:
    Code:
    {
        "IP_ADDR" = "127.0.0.1",
        "IP_PORT" = 2222
    }
    both, require() and dofile() refuse to work (since they assume a ".lua" extension); and even changing the filename to .lua extension still fails as at minimum a "return" would need to be present.

    dkjson's decode() requires a JSON string, not a JSON file and I did not see a function for reading a file.

    Any chance of allowing JSON file loading in the API? This would be hugely beneficial for re-use of data-type and object definitions between the two systems. As in the above example where I could reuse the same JSON key,value pairs to instruct the CreateHTTPRequest() as well as to spawn my web-server backed.

  2. #2
    Basic Member
    Join Date
    Dec 2016
    Posts
    73
    why not
    web_config.lua:

    return encoded json string
    just need a tiny script to convert *.json to *.lua.
    https://github.com/lenLRX/Dota2_DPPO_bots ----My ML bot work in progress

  3. #3
    Basic Member
    Join Date
    Dec 2016
    Posts
    707
    Quote Originally Posted by lenlrx View Post
    why not
    web_config.lua:
    just need a tiny script to convert *.json to *.lua.
    Sure it is trivial, just add a return on the Lua side and change extension. Then on the Python/C#/C++/whatever side just strip the return off and interpret as JSON.

    But, because it is so trivial it should be 10 min of @ChrisC time to write a JSON loader API (just slap a return before file read of a .json) and return table. We do not have access to file read in the Lua, but the API could provide it.

    This is just a small QoL API request; not a blocker

  4. #4
    Basic Member axetion's Avatar
    Join Date
    Jan 2017
    Posts
    38
    This would be real nice, currently I'm having to emit Lua code for my data which is nasty

  5. #5
    Basic Member
    Join Date
    Mar 2012
    Posts
    1,884
    And if possible a small FileExists(filePath) implementation that just returns true or false if the file exists (along with directory support in case the file is inside a directory). To avoid abuse, restricted at GetScriptDirectory() only.
    Explanations on the normal, high and very high brackets in replays: here, here & here
    Why maphacks won't work in D2: here

  6. #6
    Basic Member aveyo's Avatar
    Join Date
    Aug 2012
    Location
    EU West
    Posts
    2,779
    Having random file access is simply too dangerous no matter the safeguards, and is largely not needed since you should serve everything external over the (local) web.

    https://github.com/Elinea/dota2-StorageAPI
    It works just fine for custom games (here's an example local server implementation using node.js for Reincarnation RPG).

  7. #7
    Basic Member
    Join Date
    Mar 2012
    Posts
    1,884
    Quote Originally Posted by aveyo View Post
    https://github.com/Elinea/dota2-StorageAPI
    It works just fine for custom games (here's an example local server implementation using node.js for Reincarnation RPG).
    Except there's no GET method for HTTP Request in the bot API yet. Just POST.
    Explanations on the normal, high and very high brackets in replays: here, here & here
    Why maphacks won't work in D2: here

  8. #8
    Basic Member aveyo's Avatar
    Join Date
    Aug 2012
    Location
    EU West
    Posts
    2,779
    That's... incomplete.
    How much do you have to dance around for complex bots then?
    Sry, my bad, did not know it's either filesystem or bust

  9. #9
    Banned
    Join Date
    May 2013
    Location
    In a flying city in the sky
    Posts
    1,119
    Quote Originally Posted by The Nomad View Post
    Except there's no GET method for HTTP Request in the bot API yet. Just POST.
    LMAO

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •