-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestlua.php
More file actions
executable file
·67 lines (60 loc) · 1.98 KB
/
Copy pathtestlua.php
File metadata and controls
executable file
·67 lines (60 loc) · 1.98 KB
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
<?php
/*
@nom: testlua
@auteur: piwebpool (info@infrafast.com)
@description: running lua scripts stored in the database for test purpose only, non productive use
*/
//
require_once('configuration.php');
require_once('functions.php');
require_once('luaContext.php');
if (!$link = mysql_connect($options["database"]["host"], $options["database"]["username"], $options["database"]["password"])) {
echo 'Could not connect to mysql';
exit;
}
if (!mysql_select_db($options["database"]["name"], $link)) {
echo 'Could not select database';
exit;
}
$answer="OK";
$state="";
$concat=array("header","footer");
$i=0;
foreach ($concat as $scriptID) {
// fetch lua header and footer code
// i.e. the run() and return
$sql = "SELECT lua from scripts where id='".$scriptID."'";
$result = mysql_query($sql, $link);
if (!$result) {
$answer.="+ERROR";
$state.="+".mysql_error();
}else{
while ($row = mysql_fetch_assoc($result)) $concat[$i++]=($row['lua']);
mysql_free_result($result);
}
}
$luaFeedback="";
$scriptID="custom";
$luaFeedback.="|".$scriptID.":";
// fetch lua code from database
$sql = "SELECT lua from scripts where id='".$scriptID."'";
$result = mysql_query($sql, $link);
if (!$result) {
$answer.="+ERROR";
$state.="+".mysql_error();
}else{
$luaCode="";
while ($row = mysql_fetch_assoc($result)) $luaCode=htmlspecialchars_decode(($row['lua']));
mysql_free_result($result);
}
if ($luaCode==""){
$luaFeedback="script '".$scriptID."' is empty";
}else
// call lua execution built from Header + Content + Footer and passing the access to the pins so they can be manipulated by lua code
goLua($concat[0].$luaCode.$concat[1],$materials,$pins,$luaFeedback,$link,$scriptID);
$state.="{".$luaFeedback."}";
appendlog("LUATEST",$answer,$state, $logfilename);
// sync data to disk
exec("sync");
echo $answer.$state;
?>