Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7580131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:50:22+00:00 2026-05-30T17:50:22+00:00

I have a simulation program which repeats a set of functions in a specific

  • 0

I have a simulation program which repeats a set of functions in a specific order a large number of times and then outputs the result of some calculations based on those functions. Each function will mutate a Simulator object in some way and will take a variable number of arguments of different types. For example:

 class Simulator
{
    Simulator();
    void A(int x, double y, string z);
    void B(int x, int y);
    void C(double x);
};

I want the user to be able to specify the order in which these functions will be called as well as the arguments, and I need to be able to store this information in some sort of script for the program to follow. For example, a script could end up being translated to the following actions for the program:

Simulator mySim;
mySim.A(5, 6.0, "a string");
mySim.B(1, 1);
mySim.A(3, 4.0, "another string");
mySim.C(10.0);

Is there an efficient way of doing this? My initial thought is to have a linked list of objects, each of which stores the name of the function, as well as the arguments. The program would then traverse the list, calling each function in turn. However, this poses a couple of problems:

(a) How to store the arguments in the list, which will be different for each function (both different in quantity as well as type).

(b) It seems rather inefficient as my program will have to execute a series of if statements on every run of the simulation, in order to determine which functions to call.

Anyone have any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:50:23+00:00Added an answer on May 30, 2026 at 5:50 pm

    My suggestion: don’t invent your own scripting language/interpreter.

    If you want to quickly get started supporting user-defined scripts in a single day, check out Lua. It’s arguably one of the easiest languages to embed into a C/C++ program. With luabind, it’s even easier:

    module(L)
    [
        class<Simulator>("Simulator")
            .def("A", &Simulator::A)
            .def("B", &Simulator::B)
            .def("C", &Simulator::C)
    ];
    

    Done! Now I can run lua scripts that can create Simulator and call functions on it and get all the features of the full lua language and its base libraries, computing mathematical expressions with each call, creating user-defined functions, closures, lambdas, etc. And lua is one speed demon when it comes to scripting languages.

    I actually managed to turn a fairly large scale, commercial C++ program into a fully scriptable one with Lua in a single day. It’s so easy to embed since that’s what it was designed to do.

    There’s also Python which is quite similar to luabind if we use Boost.Python though a lot more painful with the C API and a bit more tedious to get started (we can’t just build a statically linked library and go and there’s a lot of environment variables we have to deal with like the sys.path and making sure we use the correct Python implementation for debug/release versions).

    You could also choose among other languages, but those two of the most popular ones I know of which provide C++ libraries to make binding a lot easier.

    You could also go with SWIG and support multiple scripting languages out of the box but SWIG takes quite a long time to learn since it’s got massive documentation with a lot of details you have to pay attention to since it works for many different languages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program which performs a Monte Carlo-type simulation. Currently I have written
let us have a situation in which the following program prints some 10 lines
I have a bash script that runs a simulation program written in Fortran 90,
I have a simulation that reads large binary data files that we create (10s
I have a class (simulation) which creates an instance of another class (GUI). Inside
I have a program which simulates a physical system that changes over time. I
I have a program for some scientific simulation stuff, and as such needs to
I have a situation where there is a program which is written in c++.
Situation: I have a C# program which does the following: Generate many files (replacing
I have a signal generated by a simulation program. Because the solver in this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.