summarylogtreecommitdiffstats
path: root/tolua53.patch
blob: 905e423cb4cb4991b8b839aafc1507874b72bedf (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
diff -urN ./old/toluapp/cmake/FindLua.cmake ./new/toluapp/cmake/FindLua.cmake
--- ./old/toluapp/cmake/FindLua.cmake	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/cmake/FindLua.cmake	2016-12-26 22:53:30.932644459 +0530
@@ -1,7 +1,7 @@
 # Locate Lua library
 # This module defines
 #  LUA_EXECUTABLE, if found
-#  LUA_FOUND, if false, do not try to link to Lua 
+#  LUA_FOUND, if false, do not try to link to Lua
 #  LUA_LIBRARIES
 #  LUA_INCLUDE_DIR, where to find lua.h
 #  LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8)
@@ -40,7 +40,7 @@
 IF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
   SET(_POSSIBLE_SUFFIXES "${Lua_FIND_VERSION_MAJOR}${Lua_FIND_VERSION_MINOR}" "${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}" "-${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}")
 ELSE(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
-  SET(_POSSIBLE_SUFFIXES "52" "5.2" "-5.2" "51" "5.1" "-5.1")
+  SET(_POSSIBLE_SUFFIXES "53" "5.3" "-5.3" "52" "5.2" "-5.2" "51" "5.1" "-5.1")
 ENDIF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
 
 # Set up possible search names and locations
@@ -72,7 +72,7 @@
 )
 
 # Find the lua library
-FIND_LIBRARY(LUA_LIBRARY 
+FIND_LIBRARY(LUA_LIBRARY
   NAMES ${_POSSIBLE_LUA_LIBRARY}
   HINTS
   $ENV{LUA_DIR}
@@ -108,7 +108,7 @@
 ENDIF()
 
 INCLUDE(FindPackageHandleStandardArgs)
-# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if 
+# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
 # all listed variables are TRUE
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua
                                   REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
diff -urN ./old/toluapp/config_linux.py ./new/toluapp/config_linux.py
--- ./old/toluapp/config_linux.py	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/config_linux.py	2016-12-26 22:52:23.915976292 +0530
@@ -4,7 +4,7 @@
 
 # Compiler flags (based on Debian's installation of lua)
 #LINKFLAGS = ['-g']
-CCFLAGS = ['-I/usr/include/lua50', '-O2', '-ansi', '-Wall']
+CCFLAGS = ['-O2', '-ansi', '-Wall']
 #CCFLAGS = ['-I/usr/include/lua50', '-g']
 
 # this is the default directory for installation. Files will be installed on
@@ -18,5 +18,5 @@
 prefix = '/usr/local'
 
 # libraries (based on Debian's installation of lua)
-LIBS = ['lua50', 'lualib50', 'dl', 'm']
+LIBS = ['lua', 'dl', 'm']
 
diff -urN ./old/toluapp/custom.py ./new/toluapp/custom.py
--- ./old/toluapp/custom.py	1970-01-01 05:30:00.000000000 +0530
+++ ./new/toluapp/custom.py	2016-12-26 22:52:23.915976292 +0530
@@ -0,0 +1,9 @@
+CCFLAGS = ['-O2', '-ansi']
+#LIBPATH = ['/usr/local/lib']
+LIBS = ['lua', 'dl', 'm']
+prefix = '/usr'
+build_dev=1
+tolua_bin = 'tolua++'
+tolua_lib = 'tolua++-5.2'
+TOLUAPP = 'tolua++'
+
diff -urN ./old/toluapp/SConstruct ./new/toluapp/SConstruct
--- ./old/toluapp/SConstruct	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/SConstruct	2016-12-26 22:52:23.915976292 +0530
@@ -82,6 +82,8 @@
 	header = target[:-2] + '.h'
 	pheader = Dir('.').path + '/' + header
 
+	print("Generating ", target, " from ", source)
+
 	tolua = ""
 	if bootstrap:
 		if os.name == 'nt':
diff -urN ./old/toluapp/src/bin/lua/all.lua ./new/toluapp/src/bin/lua/all.lua
--- ./old/toluapp/src/bin/lua/all.lua	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/src/bin/lua/all.lua	2016-12-26 22:52:23.915976292 +0530
@@ -1,8 +1,8 @@
 dofile(path.."compat-5.1.lua")
 dofile(path.."compat.lua")
-dofile(path.."basic.lua")
 dofile(path.."feature.lua")
 dofile(path.."verbatim.lua")
+dofile(path.."basic.lua")
 dofile(path.."code.lua")
 dofile(path.."typedef.lua")
 dofile(path.."container.lua")
diff -urN ./old/toluapp/src/bin/lua/basic.lua ./new/toluapp/src/bin/lua/basic.lua
--- ./old/toluapp/src/bin/lua/basic.lua	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/src/bin/lua/basic.lua	2016-12-26 22:52:23.915976292 +0530
@@ -75,8 +75,8 @@
 end
 
 function applyrenaming (s)
-	for i=1,getn(_renaming) do
-	 local m,n = gsub(s,_renaming[i].old,_renaming[i].new)
+	for i,v in ipairs(_renaming) do
+	 local m,n = gsub(s,v.old,v.new)
 		if n ~= 0 then
 		 return m
 		end
@@ -252,7 +252,8 @@
 -- concatenate all parameters, following output rules
 function concatparam (line, ...)
  local i=1
- while i<=arg.n do
+ local arg={...}
+ while i<=#arg do
   if _cont and not strfind(_cont,'[%(,"]') and
      strfind(arg[i],"^[%a_~]") then
 	    line = line .. ' '
@@ -263,7 +264,7 @@
   end
   i = i+1
  end
- if strfind(arg[arg.n],"[%/%)%;%{%}]$") then
+ if strfind(arg[#arg],"[%/%)%;%{%}]$") then
   _cont=nil line = line .. '\n'
  end
 	return line
@@ -272,7 +273,8 @@
 -- output line
 function output (...)
  local i=1
- while i<=arg.n do
+ local arg = {...}
+ while i<=#arg do
   if _cont and not strfind(_cont,'[%(,"]') and
      strfind(arg[i],"^[%a_~]") then
 	    write(' ')
@@ -283,7 +285,7 @@
   end
   i = i+1
  end
- if strfind(arg[arg.n],"[%/%)%;%{%}]$") then
+ if strfind(arg[#arg],"[%/%)%;%{%}]$") then
   _cont=nil write('\n')
  end
 end
@@ -373,9 +375,10 @@
 
 end
 
+
 -- called to output an error message
 function output_error_hook(...)
-	return string.format(...)
+	return string.format(table.unpack{...})
 end
 
 -- custom pushers
diff -urN ./old/toluapp/src/bin/lua/class.lua ./new/toluapp/src/bin/lua/class.lua
--- ./old/toluapp/src/bin/lua/class.lua	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/src/bin/lua/class.lua	2016-12-26 22:52:23.915976292 +0530
@@ -92,7 +92,7 @@
 	self.btype = typevar(self.base)
 	self.ctype = 'const '..self.type
 	if self.extra_bases then
-		for i=1,table.getn(self.extra_bases) do
+		for i=1,#self.extra_bases do
 			self.extra_bases[i] = typevar(self.extra_bases[i])
 		end
 	end
@@ -138,9 +138,9 @@
 -- Expects the name, the base (array) and the body of the class.
 function Class (n,p,b)
 
-	if table.getn(p) > 1 then
+	if #p > 1 then
 		b = string.sub(b, 1, -2)
-		for i=2,table.getn(p),1 do
+		for i=2,#p,1 do
 			b = b.."\n tolua_inherits "..p[i].." __"..p[i].."__;\n"
 		end
 		b = b.."\n}"
diff -urN ./old/toluapp/src/bin/lua/clean.lua ./new/toluapp/src/bin/lua/clean.lua
--- ./old/toluapp/src/bin/lua/clean.lua	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/src/bin/lua/clean.lua	2016-12-26 22:52:23.915976292 +0530
@@ -19,14 +19,14 @@
 }
 
 function mask (s)
- for i = 1,getn(MASK)  do
+ for i = 1,#MASK  do
   s = gsub(s,MASK[i][2],MASK[i][1])
  end
  return s
 end
 
 function unmask (s)
- for i = 1,getn(MASK)  do
+ for i = 1,#MASK  do
   s = gsub(s,MASK[i][1],MASK[i][2])
  end
  return s
diff -urN ./old/toluapp/src/bin/lua/compat-5.1.lua ./new/toluapp/src/bin/lua/compat-5.1.lua
--- ./old/toluapp/src/bin/lua/compat-5.1.lua	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/src/bin/lua/compat-5.1.lua	2016-12-26 22:52:23.915976292 +0530
@@ -25,10 +25,10 @@
 		end
 	end
 
-	local f = load(getfile, path)
+	local f, errmsg = load(getfile, path)
 	if not f then
 	
-		error("error loading file "..path)
+		error("error loading file "..path ..": " .. errmsg)
 	end
 	return f()
 end
diff -urN ./old/toluapp/src/bin/lua/compat.lua ./new/toluapp/src/bin/lua/compat.lua
--- ./old/toluapp/src/bin/lua/compat.lua	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/src/bin/lua/compat.lua	2016-12-26 22:52:23.919309626 +0530
@@ -40,15 +40,13 @@
   end
 end
 
-function dostring(s) return do_(loadstring(s)) end
+function dostring(s) return do_(load(s)) end
 -- function dofile(s) return do_(loadfile(s)) end
 
 -------------------------------------------------------------------
 -- Table library
 local tab = table
-foreach = tab.foreach
-foreachi = tab.foreachi
-getn = tab.getn
+getn = function (tab) return #tab end
 tinsert = tab.insert
 tremove = tab.remove
 sort = tab.sort
@@ -78,7 +76,7 @@
 frexp = math.frexp
 ldexp = math.ldexp
 log = math.log
-log10 = math.log10
+log10 = function(val) return math.log(10, val) end
 max = math.max
 min = math.min
 mod = math.mod
@@ -177,17 +175,19 @@
 
 function read (...)
   local f = _INPUT
+  local arg = {...}
   if rawtype(arg[1]) == 'userdata' then
     f = tab.remove(arg, 1)
   end
-  return f:read(unpack(arg))
+  return f:read(table.unpack(arg))
 end
 
 function write (...)
   local f = _OUTPUT
+  local arg = {...}
   if rawtype(arg[1]) == 'userdata' then
     f = tab.remove(arg, 1)
   end
-  return f:write(unpack(arg))
+  return f:write(table.unpack(arg))
 end
 
diff -urN ./old/toluapp/src/bin/lua/declaration.lua ./new/toluapp/src/bin/lua/declaration.lua
--- ./old/toluapp/src/bin/lua/declaration.lua	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/src/bin/lua/declaration.lua	2016-12-26 22:52:23.919309626 +0530
@@ -137,7 +137,7 @@
 	if b then
 
 		m = split_c_tokens(string.sub(m, 2, -2), ",")
-		for i=1, table.getn(m) do
+		for i=1, #m do
 			m[i] = string.gsub(m[i],"%s*([%*&])", "%1")
 			if not isbasic(m[i]) then
 				if not isenum(m[i]) then _, m[i] = applytypedef("", m[i]) end
@@ -522,7 +522,7 @@
  end
 
  -- check the form: mod type* name
- local s1 = gsub(s,"(%b\[\])",function (n) return gsub(n,'%*','\1') end)
+ local s1 = gsub(s,"(%b%[%])",function (n) return gsub(n,'%*','\1') end)
  t = split_c_tokens(s1,'%*')
  if t.n == 2 then
   t[2] = gsub(t[2],'\1','%*') -- restore * in dimension expression
diff -urN ./old/toluapp/src/bin/lua/feature.lua ./new/toluapp/src/bin/lua/feature.lua
--- ./old/toluapp/src/bin/lua/feature.lua	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/src/bin/lua/feature.lua	2016-12-26 22:52:23.919309626 +0530
@@ -132,7 +132,7 @@
  if not fname or fname == '' then
  	fname = self.name
  end
-  n = string.gsub(n..'_'.. (fname), "[<>:, \.%*&]", "_")
+  n = string.gsub(n..'_'.. (fname), "[<>:, \\.%*&]", "_")
 
   return n
 end
diff -urN ./old/toluapp/src/bin/lua/function.lua ./new/toluapp/src/bin/lua/function.lua
--- ./old/toluapp/src/bin/lua/function.lua	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/src/bin/lua/function.lua	2016-12-26 22:52:23.919309626 +0530
@@ -520,7 +520,7 @@
 function join(t, sep, first, last)
 
 	first = first or 1
-	last = last or table.getn(t)
+	last = last or #t
 	local lsep = ""
 	local ret = ""
 	local loop = false
diff -urN ./old/toluapp/src/bin/lua/package.lua ./new/toluapp/src/bin/lua/package.lua
--- ./old/toluapp/src/bin/lua/package.lua	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/src/bin/lua/package.lua	2016-12-26 22:52:23.919309626 +0530
@@ -39,7 +39,7 @@
  self.code = gsub(self.code,"\n%s*%$%]","\2")
  self.code = gsub(self.code,"(%b\1\2)",       function (c)
                                                tinsert(L,c)
-                                               return "\n#["..getn(L).."]#"
+                                               return "\n#[".. #L .."]#"
                                               end)
  -- avoid preprocessing embedded C code
  local C = {}
@@ -47,14 +47,14 @@
  self.code = gsub(self.code,"\n%s*%$%>","\4")
  self.code = gsub(self.code,"(%b\3\4)",       function (c)
                                                tinsert(C,c)
-                                               return "\n#<"..getn(C)..">#"
+                                               return "\n#<".. #C ..">#"
                                               end)
  -- avoid preprocessing embedded C code
  self.code = gsub(self.code,"\n%s*%$%{","\5") -- deal with embedded C code
  self.code = gsub(self.code,"\n%s*%$%}","\6")
  self.code = gsub(self.code,"(%b\5\6)",       function (c)
                                                tinsert(C,c)
-                                               return "\n#<"..getn(C)..">#"
+                                               return "\n#<".. #C..">#"
                                               end)
 
  --self.code = gsub(self.code,"\n%s*#[^d][^\n]*\n", "\n\n") -- eliminate preprocessor directives that don't start with 'd'
@@ -64,7 +64,7 @@
  local V = {}
  self.code = gsub(self.code,"\n(%s*%$[^%[%]][^\n]*)",function (v)
                                                tinsert(V,v)
-                                               return "\n#"..getn(V).."#"
+                                               return "\n#".. #V .."#"
                                               end)
 
  -- perform global substitution
@@ -152,14 +152,14 @@
 	if flags.t then
 		output("#ifndef Mtolua_typeid\n#define Mtolua_typeid(L,TI,T)\n#endif\n")
 	end
-	foreach(_usertype,function(n,v)
+	for n,v in pairs(_usertype) do
 		if (not _global_classes[v]) or _global_classes[v]:check_public_access() then
 			output(' tolua_usertype(tolua_S,"',v,'");')
 			if flags.t then
 				output(' Mtolua_typeid(tolua_S,typeid(',v,'), "',v,'");')
 			end
 		end
-	 end)
+	 end
  output('}')
  output('\n')
 end
@@ -288,7 +288,7 @@
 				local t = {code=s}
 				extra = string.gsub(extra, "^%s*,%s*", "")
 				local pars = split_c_tokens(extra, ",")
-				include_file_hook(t, fn, unpack(pars))
+				include_file_hook(t, fn, table.unpack(pars))
 				return "\n\n" .. t.code
 			else
 				error('#Invalid include directive (use $cfile, $pfile, $lfile or $ifile)')
@@ -322,7 +322,7 @@
       table.insert(chunk, string.sub(line, 3) .. "\n")
      else
       local last = 1
-      for text, expr, index in string.gfind(line, "(.-)$(%b())()") do 
+      for text, expr, index in string.gmatch(line, "(.-)$(%b())()") do 
         last = index
         if text ~= "" then
           table.insert(chunk, string.format('table.insert(__ret, %q )', text))
@@ -334,10 +334,9 @@
     end
   end
   table.insert(chunk, '\nreturn table.concat(__ret)\n')
-  local f,e = loadstring(table.concat(chunk))
+  local f,e = load(table.concat(chunk), nil, "t", _extra_parameters)
   if e then
   	error("#"..e)
   end
-  setfenv(f, _extra_parameters)
   return f()
 end
diff -urN ./old/toluapp/src/bin/lua/template_class.lua ./new/toluapp/src/bin/lua/template_class.lua
--- ./old/toluapp/src/bin/lua/template_class.lua	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/src/bin/lua/template_class.lua	2016-12-26 22:52:23.919309626 +0530
@@ -22,7 +22,7 @@
 	for i =1 , types.n do
 
 		local Il = split_c_tokens(types[i], " ")
-		if table.getn(Il) ~= table.getn(self.args) then
+		if #Il ~= #self.args then
 			error("#invalid parameter count for "..types[i])
 		end
 		local bI = self.body
@@ -31,16 +31,16 @@
 			--Tl[j] = findtype(Tl[j]) or Tl[j]
 			bI = string.gsub(bI, "([^_%w])"..self.args[j].."([^_%w])", "%1"..Il[j].."%2")
 			if self.parents then
-				for i=1,table.getn(self.parents) do
+				for i=1,#self.parents do
 					pI[i] = string.gsub(self.parents[i], "([^_%w]?)"..self.args[j].."([^_%w]?)", "%1"..Il[j].."%2")
 				end
 			end
 		end
 		--local append = "<"..string.gsub(types[i], "%s+", ",")..">"
-		local append = "<"..concat(Il, 1, table.getn(Il), ",")..">"
+		local append = "<"..concat(Il, 1, #Il, ",")..">"
 		append = string.gsub(append, "%s*,%s*", ",")
 		append = string.gsub(append, ">>", "> >")
-		for i=1,table.getn(pI) do
+		for i=1,#pI do
 			--pI[i] = string.gsub(pI[i], ">>", "> >")
 			pI[i] = resolve_template_types(pI[i])
 		end
diff -urN ./old/toluapp/src/bin/SCsub ./new/toluapp/src/bin/SCsub
--- ./old/toluapp/src/bin/SCsub	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/src/bin/SCsub	2016-12-26 22:52:42.502643375 +0530
@@ -5,8 +5,8 @@
 	]
 
 
-toluabind = env.LuaBinding('toluabind.c', 'tolua_scons.pkg', 'tolua', bootstrap = True)
+#toluabind = env.LuaBinding('toluabind.c', 'tolua_scons.pkg', 'tolua', bootstrap = True)
 
-env.bin_target = env.Program('#/bin/'+env['tolua_bin'], src + [toluabind], LIBS = ['$tolua_lib'] + env['LIBS'])
+env.bin_target = env.Program('#/bin/'+env['tolua_bin'], src, LIBS = ['$tolua_lib'] + env['LIBS'])
 
 env.bootstrap_target = env.Program('#/bin/'+env['TOLUAPP_BOOTSTRAP'], src + ['toluabind_default.c', env.lib_target_static], LIBS = env['LIBS'])
diff -urN ./old/toluapp/src/bin/tolua.c ./new/toluapp/src/bin/tolua.c
--- ./old/toluapp/src/bin/tolua.c	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/src/bin/tolua.c	2016-12-27 07:19:12.355746162 +0530
@@ -67,7 +67,11 @@
 static void add_extra (lua_State* L, char* value) {
 	int len;
 	lua_getglobal(L, "_extra_parameters");
+#if LUA_VERSION_NUM > 501
+	len = lua_rawlen(L, -1);
+#else
 	len = luaL_getn(L, -1);
+#endif
 	lua_pushstring(L, value);
 	lua_rawseti(L, -2, len+1);
 	lua_pop(L, 1);
@@ -145,7 +149,7 @@
   }
   lua_pop(L,1);
  }
-/* #define TOLUA_SCRIPT_RUN */
+#define TOLUA_SCRIPT_RUN
 #ifndef TOLUA_SCRIPT_RUN
  {
   int tolua_tolua_open (lua_State* L);
@@ -153,16 +157,17 @@
  }
 #else
  {
-  char* p;
-  char  path[BUFSIZ];
-  strcpy(path,argv[0]);
-  p = strrchr(path,'/');
-  if (p==NULL) p = strrchr(path,'\\');
-  p = (p==NULL) ? path : p+1;
-  sprintf(p,"%s","../src/bin/lua/");
-  lua_pushstring(L,path); lua_setglobal(L,"path");
-		strcat(path,"all.lua");
-  lua_dofile(L,path);
+  lua_pushstring(L, "/usr/share/toluapp/luapp/"); lua_setglobal(L,"path");
+  if (luaL_loadfile(L, "/usr/share/toluapp/luapp/all.lua") != 0) {
+    fprintf(stderr, "luaL_loadfile failed\n");
+    return 1;
+  }
+  if (lua_pcall(L, 0,0,0) != 0) {
+    const char *errmsg = lua_tostring(L, -1);
+    fprintf(stderr, "lua_pcall failed: %s\n", errmsg);
+    lua_pop(L, 1);
+    return 1;
+  }
  }
 #endif
  return 0;
diff -urN ./old/toluapp/src/lib/tolua_event.c ./new/toluapp/src/lib/tolua_event.c
--- ./old/toluapp/src/lib/tolua_event.c	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/src/lib/tolua_event.c	2016-12-26 22:52:23.919309626 +0530
@@ -23,12 +23,20 @@
 static void storeatubox (lua_State* L, int lo)
 {
 	#ifdef LUA_VERSION_NUM
+#if LUA_VERSION_NUM > 501
+		lua_getuservalue(L, lo);
+#else
 		lua_getfenv(L, lo);
+#endif
 		if (lua_rawequal(L, -1, TOLUA_NOPEER)) {
 			lua_pop(L, 1);
 			lua_newtable(L);
 			lua_pushvalue(L, -1);
+#if LUA_VERSION_NUM > 501
+			lua_setuservalue(L, lo);	/* stack: k,v,table  */
+#else
 			lua_setfenv(L, lo);	/* stack: k,v,table  */
+#endif
 		};
 		lua_insert(L, -3);
 		lua_settable(L, -3); /* on lua 5.1, we trade the "tolua_peers" lookup for a settable call */
@@ -141,7 +149,11 @@
 	{
 		/* Access alternative table */
 		#ifdef LUA_VERSION_NUM /* new macro on version 5.1 */
+#if LUA_VERSION_NUM > 501
+		lua_getuservalue(L, 1);
+#else
 		lua_getfenv(L,1);
+#endif
 		if (!lua_rawequal(L, -1, TOLUA_NOPEER)) {
 			lua_pushvalue(L, 2); /* key */
 			lua_gettable(L, -2); /* on lua 5.1, we trade the "tolua_peers" lookup for a gettable call */
@@ -420,6 +432,8 @@
 */
 TOLUA_API int class_gc_event (lua_State* L)
 {
+  if (lua_type(L,1) == LUA_TUSERDATA)
+  {
 	void* u = *((void**)lua_touserdata(L,1));
 	int top;
 	/*fprintf(stderr, "collecting: looking at %p\n", u);*/
@@ -427,7 +441,8 @@
 	lua_pushstring(L,"tolua_gc");
 	lua_rawget(L,LUA_REGISTRYINDEX);
 	*/
-	lua_pushvalue(L, lua_upvalueindex(1));
+	lua_pushstring(L,"tolua_gc");
+	lua_rawget(L,LUA_REGISTRYINDEX);   /* gc */
 	lua_pushlightuserdata(L,u);
 	lua_rawget(L,-2);            /* stack: gc umt    */
 	lua_getmetatable(L,1);       /* stack: gc umt mt */
@@ -456,6 +471,7 @@
 		lua_rawset(L,-5);           /* stack: gc umt mt */
 	}
 	lua_pop(L,3);
+  }
 	return 0;
 }
 
diff -urN ./old/toluapp/src/lib/tolua_map.c ./new/toluapp/src/lib/tolua_map.c
--- ./old/toluapp/src/lib/tolua_map.c	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/src/lib/tolua_map.c	2016-12-26 22:52:23.919309626 +0530
@@ -262,8 +262,12 @@
 
 		lua_pop(L, 1);
 		lua_pushvalue(L, TOLUA_NOPEER);
-	};
+	}
+#if LUA_VERSION_NUM > 501
+	lua_setuservalue(L, -2);
+#else
 	lua_setfenv(L, -2);
+#endif
 
 	return 0;
 };
@@ -271,7 +275,11 @@
 static int tolua_bnd_getpeer(lua_State* L) {
 
 	/* stack: userdata */
+#if LUA_VERSION_NUM > 501
+	lua_getuservalue(L, -1);
+#else
 	lua_getfenv(L, -1);
+#endif
 	if (lua_rawequal(L, -1, TOLUA_NOPEER)) {
 		lua_pop(L, 1);
 		lua_pushnil(L);
@@ -411,7 +419,11 @@
 		lua_rawget(L,-2);
 	}
 	else
+#if LUA_VERSION_NUM > 501
+	 lua_pushglobaltable(L);
+#else
 	 lua_pushvalue(L,LUA_GLOBALSINDEX);
+#endif
 }
 
 /* End module
@@ -445,7 +457,11 @@
 	else
 	{
 		/* global table */
+#if LUA_VERSION_NUM > 501
+		lua_pushglobaltable(L);
+#else
 		lua_pushvalue(L,LUA_GLOBALSINDEX);
+#endif
 	}
 	if (hasvar)
 	{
@@ -473,7 +489,11 @@
 	else
 	{
 		/* global table */
+#if LUA_VERSION_NUM > 501
+		lua_pushglobaltable(L);
+#else
 		lua_pushvalue(L,LUA_GLOBALSINDEX);
+#endif
 	}
 	if (hasvar)
 	{
diff -urN ./old/toluapp/src/lib/tolua_push.c ./new/toluapp/src/lib/tolua_push.c
--- ./old/toluapp/src/lib/tolua_push.c	2016-12-26 22:12:18.000000000 +0530
+++ ./new/toluapp/src/lib/tolua_push.c	2016-12-26 22:52:23.919309626 +0530
@@ -79,7 +79,11 @@
 
    #ifdef LUA_VERSION_NUM
    lua_pushvalue(L, TOLUA_NOPEER);
+#if LUA_VERSION_NUM > 501
+   lua_setuservalue(L, -2);
+#else
    lua_setfenv(L, -2);
+#endif
    #endif
   }
   else