Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add gras_load_environment_script & gras_function_register_default functions to gras
authorcoldpeace <coldpeace@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 5 Aug 2010 14:17:20 +0000 (14:17 +0000)
committercoldpeace <coldpeace@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 5 Aug 2010 14:17:20 +0000 (14:17 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8121 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/gras/virtu.h
src/gras/Virtu/sg_process.c

index c7b8653..43bc908 100644 (file)
@@ -20,7 +20,9 @@ SG_BEGIN_DECL()
      void gras_global_init(int *argc, char **argv);
      void gras_create_environment(const char *file);
      void gras_function_register(const char *name, xbt_main_func_t code);
+     void gras_function_register_default(xbt_main_func_t code);
      void gras_launch_application(const char *file);
+     void gras_load_environment_script(const char *file);
      void gras_clean(void);
      void gras_main(void);
 
index d6497b0..369cee6 100644 (file)
 #include "gras/Virtu/virtu_sg.h"
 #include "gras/Msg/msg_interface.h"     /* For some checks at simulation end */
 #include "gras/Transport/transport_interface.h" /* For some checks at simulation end */
-
+#if HAVE_LUA
+#include <lua.h>
+#include <lauxlib.h>
+#include <lualib.h>
+#endif
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(gras_virtu_process);
 
 static long int PID = 1;
@@ -240,6 +244,11 @@ void gras_function_register(const char *name, xbt_main_func_t code)
   SIMIX_function_register(name, code);
 }
 
+void gras_function_register_default(xbt_main_func_t code)
+{
+  SIMIX_function_register_default(code);
+}
+
 void gras_main()
 {
   /* Clean IO before the run */
@@ -257,6 +266,22 @@ void gras_launch_application(const char *file)
   SIMIX_launch_application(file);
 }
 
+void gras_load_environment_script(const char* script_file)
+{
+#ifdef HAVE_LUA
+    lua_State *L = lua_open();
+    luaL_openlibs(L);
+
+    if (luaL_loadfile(L, script_file) || lua_pcall(L, 0, 0, 0)) {
+         printf("error: %s\n", lua_tostring(L, -1));
+         return;
+       }
+#else
+    xbt_die("Lua is not available!! to call gras_load_environment_script, lua should be available...");
+#endif
+    return;
+}
+
 void gras_clean()
 {
   SIMIX_clean();