summaryrefslogtreecommitdiff
path: root/iup/srcconsole/iup_lua3.c
blob: aef041b03985fd6b51e8a6230a26c5572f8f5349 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/** \file
 * \brief Creates a Lua executable linked to all standard IUP libraries
 * If user does not provide arguments environment variable 
 * "console3.lua" will be searched. And if fails
 * internal Lua code will be executed to provide a basic interface
 * for the user.
 *
 * See Copyright Notice in "iup.h"
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "lua.h"
#include "lualib.h"   
#include "luadebug.h"

#include "iup.h"
#include "iupkey.h"
#include "iuplua.h"

#ifndef IUPLUA_NO_GL
#include "iupgl.h"
#include "iupluagl.h"
#endif

#ifndef IUPLUA_NO_CD
#include "iupcontrols.h"
#include "iupluacontrols.h"
#include "iup_pplot.h"
#include "iuplua_pplot.h"
#include <cd.h>
#include <cdlua.h>
#include <cdluaiup.h>
#endif

#ifndef IUPLUA_NO_IM
#include "iupluaim.h"
#include <imlua.h>
#endif

int main ( int argc, char **argv )
{
  IupOpen(&argc, &argv);
#ifndef IUPLUA_NO_GL
  IupGLCanvasOpen(); 
#endif
#ifndef IUPLUA_NO_CD
  IupControlsOpen();
  IupPPlotOpen();
#endif

  lua_open();

  lua_setdebug(1);

  lua_iolibopen( );
  lua_strlibopen( );
  lua_mathlibopen( );  
  
  iuplua_open( );
  iupkey_open( );
#ifndef IUPLUA_NO_GL
  iupgllua_open();
#endif
#ifndef IUPLUA_NO_CD
  iupcontrolslua_open();
  iup_pplotlua_open();
  cdlua_open();
  cdluaiup_open();
#endif
#ifndef IUPLUA_NO_IM
  iupimlua_open();
  imlua_open();
#endif

  if (argc <= 1) 
  {
    if(!iuplua_dofile("console3.lua"))
    {
#ifdef TEC_BIGENDIAN
#ifdef TEC_64
#include "loh/console3_be64.loh"
#else
#include "loh/console3_be32.loh"
#endif  
#else
#ifdef TEC_64
#ifdef WIN64
#include "loh/console3_le64w.loh"
#else
#include "loh/console3_le64.loh"
#endif  
#else
#include "loh/console3.loh"
#endif  
#endif  
    }
  }
  else
  {
    int ok = 1,
        i  = 1;

    /* Running all .lua given as arguments */
    while(ok & (i < argc))
    {
      ok = iuplua_dofile(argv[i]);
      i++;
    }

    if(!ok)
    {
      return EXIT_FAILURE;
    }
  }

#ifndef IUPLUA_NO_CD
  cdlua_close();
  IupControlsClose();
#endif
  IupClose();
  
  lua_close();
  
  return EXIT_SUCCESS;
}