Jump to content

where can I find detailed descriptions of the a_do_script() and net.dostring_in() functions?


Go to solution Solved by Actium,

Recommended Posts

Posted

Hey, guys, where can I find detailed descriptions of the a_do_script() and net.dostring_in() functions? I've been looking for a long time but still can't find it. Can someone tell me? Thank you!

Posted

Unfortunately, the DCS scripting API documentation – or the lack thereof – is incredibly disappointing. The scripting FAQ contains nothing on either function. The only other source I found is %DCS_INSTALL_DIR%/API/Sim_ControlAPI.html, which is very superficial and erroneous. Expand this spoiler at your discretion to read another short rant about the state of DCS scripting engine:

Spoiler

Changes occur without any mention in the changelog and the community managers do not respond when asked in the respective topics. Apparently, scripting engine changes do not even receive basic testing, as bug after bug after bug after bug have proven. What adds insult to injury is that reporting these bugs appears to be a total waste of time. All my recent scripting engine bug reports have gone unacknowledged.

I implemented my WebConsole.lua with the primary intent to figure out how the DCS scripting engine works through trial and error. I've summarized the understanding I developed from that in this post. Take it with a grain of salt. Relevant quote here:

On 7/26/2025 at 9:56 PM, Actium said:

DCS relies on multiple Lua interpreter instances to isolate different scripting zones/environments/namespaces from each other. They contain entirely separate global environments (_G variable). These are called lua_State in the Lua documentation and are also referred to as states in DCS' documentation. The states are isolated from each other, but some applications require to run code and get return values from other states. That is where net.dostring_in() comes in:

net.dostring_in(state, string) -> string: Executes a lua-string in a given internal lua-state and returns a string result

AFAIK, the following Lua states exist: "config", "export", "gui", "mission", "server", "scripting" (new since DCS 2.9.18; separate from a_do_script()), and "userhooks" (new since DCS 2.9.18).
Some of these states are trusted and privileged, e.g., "gui", "server", and "userhooks". These are allowed to read and write arbitrary files and call external programs, which is how SRS launches the client automatically on SRS-enabled servers. Other, unprivileged states run untrusted code from mission files, e.g., the "mission" state. Potentially dangerous Lua functions, e.g., for writing files and calling executables, are sanitized from these unprivileged states.

The a_do_script() function provides access to the actual mission scripting environment, i.e., all LUA code run via the mission editor, e.g., thru trigger. For examples of a_do_script() use, see the links here.

@BIGNEWY Please do chime in if you have any additional information and please encourage your developers to improve the documentation.

 

 

Posted
5小时前,Actium说:

Unfortunately, the DCS scripting API documentation – or the lack thereof – is incredibly disappointing. The scripting FAQ contains nothing on either function. The only other source I found is %DCS_INSTALL_DIR%/API/Sim_ControlAPI.html, which is very superficial and erroneous. Expand this spoiler at your discretion to read another short rant about the state of DCS scripting engine:

  展现隐藏的内容

Changes occur without any mention in the changelog and the community managers do not respond when asked in the respective topics. Apparently, scripting engine changes do not even receive basic testing, as bug after bug after bug after bug have proven. What adds insult to injury is that reporting these bugs appears to be a total waste of time. All my recent scripting engine bug reports have gone unacknowledged.

I implemented my WebConsole.lua with the primary intent to figure out how the DCS scripting engine works through trial and error. I've summarized the understanding I developed from that in this post. Take it with a grain of salt. Relevant quote here:

The a_do_script() function provides access to the actual mission scripting environment, i.e., all LUA code run via the mission editor, e.g., thru trigger. For examples of a_do_script() use, see the links here.

@BIGNEWY Please do chime in if you have any additional information and please encourage your developers to improve the documentation.

 

 

译文

 

I just want to obtain the data list or template of the group from mission. But it always fails. However, small lists can be output, such as the position of the target eye. Is it true that net.dostring_in() cannot output very large strings?

Posted
6 hours ago, Qazplm said:

I just want to obtain the data list or template of the group from mission.

The easier way to accomplish that would be to unzip the .miz file (it is just a regular ZIP archive file). The group templates are part of the file named mission.

6 hours ago, Qazplm said:

Is it true that net.dostring_in() cannot output very large strings?

From my experience, net.dostring_in() can return very large strings. Dozens of megabytes worked for me in the past.

Posted
1小时前,Actium说:

The easier way to accomplish that would be to unzip the .miz file (it is just a regular ZIP archive file). The group templates are part of the file named mission.

From my experience, net.dostring_in() can return very large strings. Dozens of megabytes worked for me in the past.

'''

local GetMoban=[[
function New()
  local qpa={}
  for i,k in pairs(mission.coalition.red.country[1].plane.group[2]) do
  qpa[#qpa+1]=k
  end
  return qpa
end
function ToStringEx(value)
  if value~=nil then
    if type(value)=='table' then
       return TableToStr(value)
    elseif type(value)=='string' then
       return "\'"..value.."\'"
    elseif type(value)=="function" then
       return "\'这是一个函数\'"
    else 
       return tostring(value)
    end
  end
end
function TableToStr(t)
    if t == nil then return "" end
    local retstr= "{"
    local i = 1
    for key,value in pairs(t) do
        if type(value) == "function" then
          key=nil
        end
        local signal = ","
        if i==1 then
          signal = ""
        end
        if key == i then
            retstr = retstr..signal..ToStringEx(value)
        else
            if type(key)=='number' or type(key) == 'string' then
                retstr = retstr..signal..'['..ToStringEx(key).."]="..ToStringEx(value)
            else
                if type(key)=='userdata' then
                    retstr = retstr..signal.."*s"..TableToStr(getmetatable(key)).."*e".."="..ToStringEx(value)
                else
                    retstr = retstr..signal..key.."="..ToStringEx(value)
                end
            end
        end
        i = i+1
    end
     retstr = retstr.."}"
     return retstr
end
----
local Templates=New() 
local TemplateList=TableToStr(Templates)
return TemplateList 
]]
local result, success = net.dostring_in('mission',GetMoban)
local TemplateList=loadstring("return"..result)()

'''

Is there anything wrong with my writing like this? Find the group list, convert it to a string output, and then convert it to code.

Posted

The parameter of the ne.dostring_in() function is a string, and the output is also a string. The parameter of the a_do_script() function is code and the output is a string. Is that what it means?

  • Solution
Posted

Both functions take Lua code as a string argument. net.dostring_in() can only return a string, but a_do_script() can return tables, too. However, its return value pass-thru is currently somewhat broken.

If all you want is getting a group template, just unzip the .miz file, open the extracted file named "mission" with a text editor and get the group data from there. No need to deal with traversing and converting the table programatically. Just copy & paste.

Posted
2小时前,Actium说:

Both functions take Lua code as a string argument. net.dostring_in() can only return a string, but a_do_script() can return tables, too. However, its return value pass-thru is currently somewhat broken.

If all you want is getting a group template, just unzip the .miz file, open the extracted file named "mission" with a text editor and get the group data from there. No need to deal with traversing and converting the table programatically. Just copy & paste.

Thank you. Finally, I'd like to ask, what could be the reason for this? [string"..."] :5: stack overflow

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...