-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.c
More file actions
79 lines (66 loc) · 2.45 KB
/
script.c
File metadata and controls
79 lines (66 loc) · 2.45 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
68
69
70
71
72
73
74
75
76
77
78
79
#include <cairo/cairo.h>
#include "warning.h"
#include "directories.h"
#include "script.h"
#include "levelscript.h"
#include "object.h"
#include "gener.h"
#include "layers.h"
#include "draw.h"
static void setluaint(lua_State *L, char *name, int value)
// nastavi ve skriptu do daneho nazvu promenne dane cislo.
{
lua_pushinteger(L, value);
lua_setglobal(L, name);
}
static void setluastring(lua_State *L, char *name, char *str)
// nastavi ve skriptu do daneho nazvu promenne dany string.
{
lua_pushstring(L, str);
lua_setglobal(L, name);
}
void setluadirs(lua_State *L)
// Nastavi promenne C_datadir a C_homedir (vyuzivano i v menuscript)
{
setluastring(L, "C_datadir", datafile(""));
if(homedir) setluastring(L, "C_homedir", homedir);
}
void *my_luaL_checkludata(lua_State *L, int narg)
/* V klasicke luaxlib funkce, ktera otestuje ludata, chybi.
Pouziti stejne jako ostatni luaL_check... */
{
luaL_checktype(L, narg, LUA_TLIGHTUSERDATA);
return lua_touserdata(L, narg);
}
void initlua() // inicializuje luastat
{
int error;
luastat = luaL_newstate();
luaL_openlibs(luastat); // nacteni zakladnich funkci
// predani C-ckovych funkci skriptu
lua_register(luastat, "C_setroomsize", script_setroomsize);
lua_register(luastat, "C_openpng", script_openpng);
lua_register(luastat, "C_new_object", script_new_object);
lua_register(luastat, "C_flip_object", script_flip_object);
lua_register(luastat, "C_start_active_fish", script_start_active_fish);
lua_register(luastat, "C_set_codename", script_set_codename);
lua_register(luastat, "C_new_layer", script_new_layer);
lua_register(luastat, "C_load_png_image", script_load_png_image);
lua_register(luastat, "C_setlayerimage", script_setlayerimage);
lua_register(luastat, "C_generwall", script_generwall);
lua_register(luastat, "C_genersteel", script_genersteel);
lua_register(luastat, "C_genernormal", script_genernormal);
// predani hodnot typu objektu skriptu
setluaint(luastat, "C_SMALL", SMALL);
setluaint(luastat, "C_BIG", BIG);
setluaint(luastat, "C_SOLID", SOLID);
setluaint(luastat, "C_STEEL", STEEL);
setluaint(luastat, "C_LIGHT", LIGHT);
setluadirs(luastat); // predani cest k adresarum
error = luaL_dofile(luastat, datafile("scripts/levelscript.lua")); // nacteni hlavniho souboru
if(error){
const char *message = lua_tostring(luastat, -1);
warning("LUA: %s\n", message);
lua_pop(luastat, 1);
}
}