Rev 539 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log
Rev 539 | Rev 1537 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* |
1 | /* |
2 | ** Lua binding: sjasm |
- | |
3 | ** Generated automatically by tolua++-1.0.92 on 11/06/08 00:50:38. |
- | |
4 | */ |
- | |
5 | 2 | ||
- | 3 | SjASMPlus Z80 Cross Compiler - modified - lua scripting module |
|
- | 4 | ||
- | 5 | Copyright (c) 2006 Sjoerd Mastijn (original SW) |
|
- | 6 | Copyright (c) 2022 Peter Ped Helcmanovsky (lua scripting module) |
|
- | 7 | ||
- | 8 | This software is provided 'as-is', without any express or implied warranty. |
|
- | 9 | In no event will the authors be held liable for any damages arising from the |
|
6 | #ifndef __cplusplus |
10 | use of this software. |
- | 11 | ||
- | 12 | Permission is granted to anyone to use this software for any purpose, |
|
- | 13 | including commercial applications, and to alter it and redistribute it freely, |
|
7 | #include "stdlib.h" |
14 | subject to the following restrictions: |
8 | #endif |
15 | |
- | 16 | 1. The origin of this software must not be misrepresented; you must not claim |
|
- | 17 | that you wrote the original software. If you use this software in a product, |
|
- | 18 | an acknowledgment in the product documentation would be appreciated but is |
|
9 | #include "string.h" |
19 | not required. |
10 | 20 | ||
- | 21 | 2. Altered source versions must be plainly marked as such, and must not be |
|
11 | #include "tolua++.h" |
22 | misrepresented as being the original software. |
12 | 23 | ||
13 | /* Exported function */ |
24 | 3. This notice may not be removed or altered from any source distribution. |
- | 25 | ||
- | 26 | */ |
|
- | 27 | ||
14 | TOLUA_API int tolua_sjasm_open (lua_State* tolua_S); |
28 | // lua_sjasm.cpp |
15 | 29 | ||
16 | #include "sjdefs.h" |
30 | #include "sjdefs.h" |
17 | using namespace Options; |
- | |
18 | 31 | ||
19 | /* function to register type */ |
32 | #ifdef USE_LUA |
20 | static void tolua_reg_types (lua_State* tolua_S) |
33 | |
21 | { |
34 | #include "lua.hpp" |
22 | tolua_usertype(tolua_S,"TCHAR"); |
35 | #include "LuaBridge/LuaBridge.h" |
23 | } |
36 | |
24 | 37 | static lua_State *LUA = nullptr; |
|
25 | /* function: DefineTable.Get */ |
38 | |
26 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_get_define00 |
39 | static const char* lua_err_prefix = "[LUA] "; |
27 | static int tolua_sjasm_sj_get_define00(lua_State* tolua_S) |
40 | |
28 | { |
41 | // extra lua script inserting interface (sj.something) entry functions |
29 | #ifndef TOLUA_RELEASE |
42 | // for functions with optional arguments, like error and warning |
30 | tolua_Error tolua_err; |
43 | // (as LuaBridge2.6 doesn't offer that type of binding as far as I can tell) |
31 | if ( |
44 | // Sidestepping LuaBridge write-protection by "rawset" the end point into it |
32 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
45 | static const char* binding_script_name = "lua_sjasm.cpp"; |
33 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
46 | static constexpr int binding_script_line = __LINE__; |
34 | ) |
47 | static const std::string lua_impl_init_bindings_script = R"BINDING_LUA( |
35 | goto tolua_lerror; |
48 | rawset(sj,"error",function(m,v)sj.error_i(m or "no message",v)end) |
36 | else |
49 | rawset(sj,"warning",function(m,v)sj.warning_i(m or "no message",v)end) |
37 | #endif |
50 | rawset(sj,"insert_define",function(n,v)return sj.insert_define_i(n,v)end) |
38 | { |
51 | rawset(sj,"exit",function(e)return sj.exit_i(e or 1)end) |
39 | char* tolua_var_1 = ((char*) tolua_tostring(tolua_S,1,0)); |
52 | rawset(sj,"set_device",function(i,t)return sj.set_device_i(i or "NONE",t or 0)end) |
40 | { |
53 | rawset(zx,"trdimage_create",function(n,l)return zx.trdimage_create_i(n,l)end) |
41 | char* tolua_ret = (char*) DefineTable.Get(tolua_var_1); |
54 | rawset(zx,"trdimage_add_file",function(t,f,s,l,a,r)return zx.trdimage_add_file_i(t,f,s,l,a or -1,r or false)end) |
42 | tolua_pushstring(tolua_S,(const char*)tolua_ret); |
55 | )BINDING_LUA"; |
43 | } |
56 | |
44 | } |
57 | static void lua_impl_fatalError(lua_State *L) { |
45 | return 1; |
58 | Error((char *)lua_tostring(L, -1), NULL, FATAL); |
46 | #ifndef TOLUA_RELEASE |
59 | } |
47 | tolua_lerror: |
60 | |
48 | tolua_error(tolua_S,"#ferror in function 'get_define'.",&tolua_err); |
61 | static std::vector<TextFilePos> scripts_origin; |
49 | return 0; |
62 | |
50 | #endif |
63 | static char internal_script_name[LINEMAX]; |
51 | } |
64 | |
52 | #endif //#ifndef TOLUA_DISABLE |
65 | static const char* lua_impl_get_script_name(const TextFilePos & srcPos) { |
53 | 66 | sprintf(internal_script_name, "script %u", uint32_t(scripts_origin.size())); |
|
54 | /* function: DefineTable.Replace */ |
67 | scripts_origin.push_back(srcPos); |
55 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_insert_define00 |
68 | return internal_script_name; |
56 | static int tolua_sjasm_sj_insert_define00(lua_State* tolua_S) |
69 | } |
57 | { |
70 | |
58 | #ifndef TOLUA_RELEASE |
71 | static bool isInlinedScript(TextFilePos & errorPos, const char* script_name) { |
59 | tolua_Error tolua_err; |
72 | // return false when the script is external (real file name) |
60 | if ( |
73 | if (script_name != strstr(script_name, "[string \"script ")) return false; |
61 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
74 | // inlined script, find it's origin and add line number to that |
62 | !tolua_isstring(tolua_S,2,0,&tolua_err) || |
75 | int scriptNumber = atoi(script_name + 16); |
63 | !tolua_isnoobj(tolua_S,3,&tolua_err) |
76 | if (scriptNumber < 0 || int(scripts_origin.size()) <= scriptNumber) return false; |
64 | ) |
77 | errorPos = scripts_origin.at(scriptNumber); |
65 | goto tolua_lerror; |
78 | return true; |
66 | else |
79 | } |
67 | #endif |
80 | |
68 | { |
81 | // adds current source position in lua script + full stack depth onto sourcePosStack |
69 | char* tolua_var_2 = ((char*) tolua_tostring(tolua_S,1,0)); |
82 | // = makes calls to Error/Warning API to display more precise error lines in lua scripts |
70 | char* tolua_var_3 = ((char*) tolua_tostring(tolua_S,2,0)); |
83 | static int addLuaSourcePositions() { |
71 | { |
84 | // find all *known* inlined/standalone script names and line numbers on the lua stack |
72 | bool tolua_ret = (bool) DefineTable.Replace(tolua_var_2,tolua_var_3); |
85 | assert(LUA); |
73 | tolua_pushboolean(tolua_S,(bool)tolua_ret); |
86 | lua_Debug ar; |
74 | } |
87 | source_positions_t luaPosTemp; |
75 | } |
88 | luaPosTemp.reserve(16); |
76 | return 1; |
89 | int level = 1; // level 0 is "C" space, ignore that always |
77 | #ifndef TOLUA_RELEASE |
90 | while (lua_getstack(LUA, level, &ar)) { // as long lua stack level are available |
78 | tolua_lerror: |
91 | if (!lua_getinfo(LUA, "Sl", &ar)) break; // not enough info about current level |
79 | tolua_error(tolua_S,"#ferror in function 'insert_define'.",&tolua_err); |
92 | |
80 | return 0; |
93 | //assert(level || !strcmp("[C]", ar.short_src)); //TODO: verify if ever upgrading to newer lua |
81 | #endif |
94 | //if (!strcmp("[C]", ar.short_src)) { ++level; continue; } |
82 | } |
95 | |
83 | #endif //#ifndef TOLUA_DISABLE |
96 | TextFilePos levelErrorPos; |
84 | 97 | if (isInlinedScript(levelErrorPos, ar.short_src)) { |
|
85 | /* function: LuaGetLabel */ |
98 | levelErrorPos.line += ar.currentline; |
86 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_get_label00 |
99 | } else { |
87 | static int tolua_sjasm_sj_get_label00(lua_State* tolua_S) |
100 | levelErrorPos.newFile(ArchiveFilename(ar.short_src)); |
88 | { |
101 | levelErrorPos.line = ar.currentline; |
89 | #ifndef TOLUA_RELEASE |
102 | } |
90 | tolua_Error tolua_err; |
103 | luaPosTemp.push_back(levelErrorPos); |
91 | if ( |
104 | ++level; |
92 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
105 | } |
93 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
106 | |
94 | ) |
107 | // add all lua positions in reversed order to sourcePosStack (hide binding script if anything else is available) |
95 | goto tolua_lerror; |
108 | bool hide_binding = (2 <= luaPosTemp.size()) && !strcmp(binding_script_name, luaPosTemp[0].filename); |
96 | else |
109 | source_positions_t::iterator stop = hide_binding ? luaPosTemp.begin() + 1 : luaPosTemp.begin(); |
97 | #endif |
110 | source_positions_t::iterator i = luaPosTemp.end(); |
98 | { |
111 | while (i-- != stop) sourcePosStack.push_back(*i); |
99 | char* tolua_var_4 = ((char*) tolua_tostring(tolua_S,1,0)); |
112 | |
100 | { |
113 | return luaPosTemp.end() - stop; |
101 | int tolua_ret = (int) LuaGetLabel(tolua_var_4); |
114 | } |
102 | tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); |
115 | |
103 | } |
116 | static void removeLuaSourcePositions(int to_remove) { |
104 | } |
117 | while (to_remove--) sourcePosStack.pop_back(); // restore sourcePosStack to original state |
105 | return 1; |
118 | } |
106 | #ifndef TOLUA_RELEASE |
119 | |
107 | tolua_lerror: |
120 | // skips file+line_number info (but will adjust global LuaStartPos data for Error output) |
108 | tolua_error(tolua_S,"#ferror in function 'get_label'.",&tolua_err); |
121 | static TextFilePos lua_impl_splitLuaErrorMessage(const char*& LuaError) { |
109 | return 0; |
122 | TextFilePos luaErrorPos("?"); |
110 | #endif |
123 | if (!sourcePosStack.empty()) luaErrorPos = sourcePosStack.back(); |
111 | } |
124 | if (nullptr == LuaError) return luaErrorPos; |
112 | #endif //#ifndef TOLUA_DISABLE |
125 | |
113 | 126 | const char* colonPos = strchr(LuaError, ':'); |
|
114 | /* function: LabelTable.Insert */ |
127 | const char* colon2Pos = nullptr != colonPos ? strchr(colonPos+1, ':') : nullptr; |
115 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_insert_label00 |
128 | if (nullptr == colonPos || nullptr == colon2Pos) return luaErrorPos; // error, format not recognized |
116 | static int tolua_sjasm_sj_insert_label00(lua_State* tolua_S) |
129 | |
117 | { |
130 | int lineNumber = atoi(colonPos + 1); |
118 | #ifndef TOLUA_RELEASE |
131 | if (isInlinedScript(luaErrorPos, LuaError)) { |
119 | tolua_Error tolua_err; |
132 | luaErrorPos.line += lineNumber; |
120 | if ( |
133 | } else { |
121 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
134 | // standalone script, use file name and line number as is (if provided by lua error) |
122 | !tolua_isnumber(tolua_S,2,0,&tolua_err) || |
135 | STRNCPY(internal_script_name, LINEMAX, LuaError, colonPos - LuaError); |
123 | !tolua_isboolean(tolua_S,3,1,&tolua_err) || |
136 | luaErrorPos.newFile(ArchiveFilename(internal_script_name)); |
124 | !tolua_isboolean(tolua_S,4,1,&tolua_err) || |
137 | luaErrorPos.line = lineNumber; |
125 | !tolua_isnoobj(tolua_S,5,&tolua_err) |
138 | } |
126 | ) |
139 | |
127 | goto tolua_lerror; |
140 | // advance beyond filename and line in LuaError pointer |
128 | else |
141 | LuaError = colon2Pos + 1; |
129 | #endif |
142 | while (White(*LuaError)) ++LuaError; |
130 | { |
143 | return luaErrorPos; |
131 | char* tolua_var_5 = ((char*) tolua_tostring(tolua_S,1,0)); |
144 | } |
132 | unsigned int tolua_var_6 = ((unsigned int) tolua_tonumber(tolua_S,2,0)); |
145 | |
133 | bool tolua_var_7 = ((bool) tolua_toboolean(tolua_S,3,false)); |
146 | static void lua_impl_showLoadError(const EStatus type) { |
134 | bool tolua_var_8 = ((bool) tolua_toboolean(tolua_S,4,false)); |
147 | const char *msgp = lua_tostring(LUA, -1); |
135 | bool tolua_var_9 = ((bool) tolua_toboolean(tolua_S,5,false)); |
148 | sourcePosStack.push_back(lua_impl_splitLuaErrorMessage(msgp)); |
136 | { |
149 | Error(msgp, nullptr, type); |
137 | bool tolua_ret = (bool) LabelTable.Insert(tolua_var_5,tolua_var_6,tolua_var_7,tolua_var_8,tolua_var_9); |
150 | sourcePosStack.pop_back(); |
138 | tolua_pushboolean(tolua_S,(bool)tolua_ret); |
151 | lua_pop(LUA, 1); |
139 | } |
152 | } |
140 | } |
153 | |
141 | return 1; |
154 | static aint lua_sj_calc(const char *str) { |
142 | #ifndef TOLUA_RELEASE |
155 | int positionsAdded = addLuaSourcePositions(); // add known script positions to sourcePosStack vector |
143 | tolua_lerror: |
156 | |
144 | tolua_error(tolua_S,"#ferror in function 'insert_label'.",&tolua_err); |
157 | // substitute defines + macro_args in the `str` first (preserve original global variables) |
145 | return 0; |
158 | char* const oldSubstitutedLine = substitutedLine; |
146 | #endif |
159 | const int oldComlin = comlin; |
147 | } |
160 | comlin = 0; |
148 | #endif //#ifndef TOLUA_DISABLE |
161 | char* tmp = nullptr, * tmp2 = nullptr; |
149 | 162 | if (sline[0]) { |
|
150 | /* get function: CurAddress */ |
163 | tmp = STRDUP(sline); |
151 | #ifndef TOLUA_DISABLE_tolua_get_sj_unsigned_current_address |
164 | if (nullptr == tmp) ErrorOOM(); |
152 | static int tolua_get_sj_unsigned_current_address(lua_State* tolua_S) |
165 | } |
153 | { |
166 | if (sline2[0]) { |
154 | tolua_pushnumber(tolua_S,(lua_Number)CurAddress); |
167 | tmp2 = STRDUP(sline2); |
155 | return 1; |
168 | if (nullptr == tmp2) ErrorOOM(); |
156 | } |
169 | } |
157 | #endif //#ifndef TOLUA_DISABLE |
170 | // non-const copy of input string for ReplaceDefine argument |
158 | 171 | //TODO: v2.x, rewrite whole parser of sjasmplus to start with const input to avoid such copies |
|
159 | /* get function: WarningCount */ |
172 | char* luaInput = STRDUP(str ? str : ""); |
160 | #ifndef TOLUA_DISABLE_tolua_get_sj_warning_count |
173 | char* substitutedStr = ReplaceDefine(luaInput); |
161 | static int tolua_get_sj_warning_count(lua_State* tolua_S) |
174 | |
162 | { |
175 | // evaluate the expression |
163 | tolua_pushnumber(tolua_S,(lua_Number)WarningCount); |
176 | aint val; |
164 | return 1; |
177 | int parseResult = ParseExpression(substitutedStr, val); |
165 | } |
178 | free(luaInput); |
166 | #endif //#ifndef TOLUA_DISABLE |
179 | |
167 | 180 | // restore any global values affected by substitution |
|
168 | /* get function: ErrorCount */ |
181 | sline[0] = 0; |
169 | #ifndef TOLUA_DISABLE_tolua_get_sj_error_count |
182 | if (tmp) { |
170 | static int tolua_get_sj_error_count(lua_State* tolua_S) |
183 | STRCPY(sline, LINEMAX2, tmp); |
171 | { |
184 | free(tmp); |
172 | tolua_pushnumber(tolua_S,(lua_Number)ErrorCount); |
185 | } |
173 | return 1; |
186 | sline2[0] = 0; |
174 | } |
187 | if (tmp2) { |
175 | #endif //#ifndef TOLUA_DISABLE |
188 | STRCPY(sline2, LINEMAX2, tmp2); |
176 | 189 | free(tmp2); |
|
177 | /* function: LuaShellExec */ |
190 | } |
178 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_shellexec00 |
191 | substitutedLine = oldSubstitutedLine; |
179 | static int tolua_sjasm_sj_shellexec00(lua_State* tolua_S) |
192 | comlin = oldComlin; |
180 | { |
193 | |
181 | #ifndef TOLUA_RELEASE |
194 | removeLuaSourcePositions(positionsAdded); |
182 | tolua_Error tolua_err; |
195 | return parseResult ? val : 0; |
183 | if ( |
196 | } |
184 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
197 | |
185 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
198 | static void parse_line(const char* str, bool parseLabels) { |
186 | ) |
199 | int positionsAdded = addLuaSourcePositions(); // add known script positions to sourcePosStack vector |
187 | goto tolua_lerror; |
200 | |
188 | else |
201 | // preserve current actual line which will be parsed next |
189 | #endif |
202 | char *oldLine = STRDUP(line); |
190 | { |
203 | if (nullptr == oldLine) ErrorOOM(); |
191 | char* command = ((char*) tolua_tostring(tolua_S,1,0)); |
204 | char *oldEolComment = eolComment; |
192 | { |
205 | |
- | 206 | // inject new line from Lua call and assemble it |
|
- | 207 | STRCPY(line, LINEMAX, str ? str : ""); |
|
- | 208 | eolComment = nullptr; |
|
- | 209 | ParseLineSafe(parseLabels); |
|
- | 210 | ||
- | 211 | // restore the original line |
|
- | 212 | STRCPY(line, LINEMAX, oldLine); |
|
- | 213 | eolComment = oldEolComment; |
|
- | 214 | free(oldLine); |
|
- | 215 | ||
- | 216 | removeLuaSourcePositions(positionsAdded); |
|
- | 217 | } |
|
- | 218 | ||
- | 219 | static void lua_sj_parse_line(const char *str) { |
|
- | 220 | parse_line(str, true); |
|
- | 221 | } |
|
- | 222 | ||
- | 223 | static void lua_sj_parse_code(const char *str) { |
|
- | 224 | parse_line(str, false); |
|
- | 225 | } |
|
- | 226 | ||
- | 227 | static void lua_sj_error(const char* message, const char* value = nullptr) { |
|
- | 228 | int positionsAdded = addLuaSourcePositions(); // add known script positions to sourcePosStack vector |
|
- | 229 | Error(message, value, ALL); |
|
- | 230 | removeLuaSourcePositions(positionsAdded); |
|
- | 231 | } |
|
- | 232 | ||
- | 233 | static void lua_sj_warning(const char* message, const char* value = nullptr) { |
|
- | 234 | int positionsAdded = addLuaSourcePositions(); // add known script positions to sourcePosStack vector |
|
- | 235 | Warning(message, value, W_ALL); |
|
- | 236 | removeLuaSourcePositions(positionsAdded); |
|
- | 237 | } |
|
- | 238 | ||
- | 239 | static const char* lua_sj_get_define(const char* name, bool macro_args = false) { |
|
- | 240 | const char* macro_res = (macro_args && macrolabp) ? MacroDefineTable.getverv(name) : nullptr; |
|
- | 241 | return macro_res ? macro_res : DefineTable.Get(name); |
|
- | 242 | } |
|
- | 243 | ||
- | 244 | static bool lua_sj_insert_define(const char* name, const char* value) { |
|
- | 245 | // wrapper to resolve member-function call (without std::function wrapping lambda, just to KISS) |
|
- | 246 | char* lua_name = const_cast<char*>(name); //TODO v2.x avoid const_cast like this |
|
- | 247 | char* id = name ? GetID(lua_name) : nullptr; |
|
- | 248 | if (nullptr == id) return false; |
|
- | 249 | return DefineTable.Replace(id, value ? value : ""); |
|
- | 250 | } |
|
- | 251 | ||
- | 252 | static int lua_sj_get_label(const char *name) { |
|
- | 253 | if (nullptr == name) return -1; |
|
- | 254 | aint val; |
|
- | 255 | int positionsAdded = addLuaSourcePositions(); // add known script positions to sourcePosStack vector |
|
- | 256 | char* n = const_cast<char*>(name); //TODO try to get rid of const_cast, LuaBridge requires const char* to understand it as lua string |
|
- | 257 | if (!GetLabelValue(n, val)) val = -1; |
|
- | 258 | removeLuaSourcePositions(positionsAdded); |
|
- | 259 | return val; |
|
- | 260 | } |
|
- | 261 | ||
- | 262 | static bool lua_sj_insert_label(const char *name, int address) { |
|
- | 263 | int positionsAdded = addLuaSourcePositions(); // add known script positions to sourcePosStack vector |
|
- | 264 | std::unique_ptr<char[]> fullName(ValidateLabel(name, false, false)); |
|
- | 265 | removeLuaSourcePositions(positionsAdded); |
|
- | 266 | if (nullptr == fullName.get()) return false; |
|
- | 267 | return LabelTable.Insert(name, address); |
|
- | 268 | } |
|
- | 269 | ||
- | 270 | static void lua_sj_shellexec(const char *command) { |
|
- | 271 | int positionsAdded = addLuaSourcePositions(); // add known script positions to sourcePosStack vector |
|
193 | LuaShellExec(command); |
272 | LuaShellExec(command); |
- | 273 | removeLuaSourcePositions(positionsAdded); |
|
194 | } |
274 | } |
- | 275 | ||
- | 276 | static bool lua_sj_set_page(aint n) { |
|
- | 277 | int positionsAdded = addLuaSourcePositions(); // add known script positions to sourcePosStack vector |
|
- | 278 | if (!DeviceID) Warning("sj.set_page: only allowed in real device emulation mode (See DEVICE)"); |
|
- | 279 | bool result = DeviceID && dirPageImpl("sj.set_page", n); |
|
- | 280 | removeLuaSourcePositions(positionsAdded); |
|
- | 281 | return result; |
|
- | 282 | } |
|
- | 283 | ||
- | 284 | static bool lua_sj_set_slot(aint n) { |
|
- | 285 | int positionsAdded = addLuaSourcePositions(); // add known script positions to sourcePosStack vector |
|
- | 286 | bool result = false; |
|
- | 287 | if (!DeviceID) { |
|
- | 288 | Warning("sj.set_slot: only allowed in real device emulation mode (See DEVICE)"); |
|
- | 289 | } else { |
|
- | 290 | n = Device->SlotNumberFromPreciseAddress(n); |
|
- | 291 | result = Device->SetSlot(n); |
|
- | 292 | if (!result) { |
|
- | 293 | char buf[LINEMAX]; |
|
- | 294 | SPRINTF1(buf, LINEMAX, "sj.set_slot: Slot number must be in range 0..%u", Device->SlotsCount - 1); |
|
- | 295 | Error(buf); |
|
- | 296 | } |
|
- | 297 | } |
|
- | 298 | removeLuaSourcePositions(positionsAdded); |
|
- | 299 | return result; |
|
- | 300 | } |
|
- | 301 | ||
- | 302 | static bool lua_sj_set_device(const char* id, const aint ramtop = 0) { |
|
- | 303 | int positionsAdded = addLuaSourcePositions(); // add known script positions to sourcePosStack vector |
|
- | 304 | // refresh source position of first DEVICE directive (to make global-device detection work correctly) |
|
- | 305 | if (1 == ++deviceDirectivesCount) { |
|
- | 306 | assert(!sourcePosStack.empty()); |
|
- | 307 | globalDeviceSourcePos = sourcePosStack.back(); |
|
- | 308 | } |
|
- | 309 | // check for nullptr id?? |
|
- | 310 | bool result = SetDevice(id, ramtop); |
|
- | 311 | removeLuaSourcePositions(positionsAdded); |
|
- | 312 | return result; |
|
195 | } |
313 | } |
196 | return 0; |
- | |
197 | #ifndef TOLUA_RELEASE |
- | |
198 | tolua_lerror: |
- | |
199 | tolua_error(tolua_S,"#ferror in function 'shellexec'.",&tolua_err); |
- | |
200 | return 0; |
- | |
201 | #endif |
- | |
202 | } |
- | |
203 | #endif //#ifndef TOLUA_DISABLE |
- | |
204 | - | ||
205 | /* function: TRD_SaveEmpty */ |
- | |
206 | #ifndef TOLUA_DISABLE_tolua_sjasm_zx_trdimage_create00 |
- | |
207 | static int tolua_sjasm_zx_trdimage_create00(lua_State* tolua_S) |
- | |
208 | { |
- | |
209 | #ifndef TOLUA_RELEASE |
- | |
210 | tolua_Error tolua_err; |
- | |
211 | if ( |
- | |
212 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
- | |
213 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
- | |
214 | ) |
- | |
215 | goto tolua_lerror; |
- | |
216 | else |
- | |
217 | #endif |
- | |
218 | { |
- | |
219 | char* fname = ((char*) tolua_tostring(tolua_S,1,0)); |
- | |
220 | { |
- | |
221 | int tolua_ret = (int) TRD_SaveEmpty(fname, nullptr); |
- | |
222 | tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); |
- | |
223 | } |
- | |
224 | } |
- | |
225 | return 1; |
- | |
226 | #ifndef TOLUA_RELEASE |
- | |
227 | tolua_lerror: |
- | |
228 | tolua_error(tolua_S,"#ferror in function 'trdimage_create'.",&tolua_err); |
- | |
229 | return 0; |
- | |
230 | #endif |
- | |
231 | } |
- | |
232 | #endif //#ifndef TOLUA_DISABLE |
- | |
233 | - | ||
234 | /* function: TRD_AddFile */ |
- | |
235 | #ifndef TOLUA_DISABLE_tolua_sjasm_zx_trdimage_add_file00 |
- | |
236 | static int tolua_sjasm_zx_trdimage_add_file00(lua_State* tolua_S) |
- | |
237 | { |
- | |
238 | #ifndef TOLUA_RELEASE |
- | |
239 | tolua_Error tolua_err; |
- | |
240 | if ( |
- | |
241 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
- | |
242 | !tolua_isstring(tolua_S,2,0,&tolua_err) || |
- | |
243 | !tolua_isnumber(tolua_S,3,0,&tolua_err) || |
- | |
244 | !tolua_isnumber(tolua_S,4,0,&tolua_err) || |
- | |
245 | !tolua_isnumber(tolua_S,5,0,&tolua_err) || |
- | |
246 | !tolua_isboolean(tolua_S,6,0,&tolua_err) || |
- | |
247 | !tolua_isnoobj(tolua_S,7,&tolua_err) |
- | |
248 | ) |
- | |
249 | goto tolua_lerror; |
- | |
250 | else |
- | |
251 | #endif |
- | |
252 | { |
- | |
253 | char* fname = ((char*) tolua_tostring(tolua_S,1,0)); |
- | |
254 | char* fhobname = ((char*) tolua_tostring(tolua_S,2,0)); |
- | |
255 | int start = ((int) tolua_tonumber(tolua_S,3,0)); |
- | |
256 | int length = ((int) tolua_tonumber(tolua_S,4,0)); |
- | |
257 | int autostart = ((int) tolua_tonumber(tolua_S,5,0)); |
- | |
258 | bool replace = ((int) tolua_toboolean(tolua_S,6,0)); |
- | |
259 | { |
- | |
260 | int tolua_ret = (int) TRD_AddFile(fname,fhobname,start,length,autostart,replace,false); |
- | |
261 | tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); |
- | |
262 | } |
- | |
263 | } |
- | |
264 | return 1; |
- | |
265 | #ifndef TOLUA_RELEASE |
- | |
266 | tolua_lerror: |
- | |
267 | tolua_error(tolua_S,"#ferror in function 'trdimage_add_file'.",&tolua_err); |
- | |
268 | return 0; |
- | |
269 | #endif |
- | |
270 | } |
- | |
271 | #endif //#ifndef TOLUA_DISABLE |
- | |
272 | - | ||
273 | /* function: SaveSNA_ZX */ |
- | |
274 | #ifndef TOLUA_DISABLE_tolua_sjasm_zx_save_snapshot_sna12800 |
- | |
275 | static int tolua_sjasm_zx_save_snapshot_sna12800(lua_State* tolua_S) |
- | |
276 | { |
- | |
277 | #ifndef TOLUA_RELEASE |
- | |
278 | tolua_Error tolua_err; |
- | |
279 | if ( |
- | |
280 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
- | |
281 | !tolua_isnumber(tolua_S,2,0,&tolua_err) || |
- | |
282 | !tolua_isnoobj(tolua_S,3,&tolua_err) |
- | |
283 | ) |
- | |
284 | goto tolua_lerror; |
- | |
285 | else |
- | |
286 | #endif |
- | |
287 | { |
- | |
288 | char* fname = ((char*) tolua_tostring(tolua_S,1,0)); |
- | |
289 | unsigned short start = ((unsigned short) tolua_tonumber(tolua_S,2,0)); |
- | |
290 | { |
- | |
291 | int tolua_ret = (int) SaveSNA_ZX(fname,start); |
- | |
292 | tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); |
- | |
293 | } |
- | |
294 | } |
- | |
295 | return 1; |
- | |
296 | #ifndef TOLUA_RELEASE |
- | |
297 | tolua_lerror: |
- | |
298 | tolua_error(tolua_S,"#ferror in function 'save_snapshot_sna128'.",&tolua_err); |
- | |
299 | return 0; |
- | |
300 | #endif |
- | |
301 | } |
- | |
302 | #endif //#ifndef TOLUA_DISABLE |
- | |
303 | - | ||
304 | /* get function: CurrentDirectory */ |
- | |
305 | #ifndef TOLUA_DISABLE_tolua_get_sj_current_path |
- | |
306 | static int tolua_get_sj_current_path(lua_State* tolua_S) |
- | |
307 | { |
- | |
308 | tolua_pushstring(tolua_S,(const char*)CurrentDirectory); |
- | |
309 | return 1; |
- | |
310 | } |
- | |
311 | #endif //#ifndef TOLUA_DISABLE |
- | |
312 | - | ||
313 | /* function: ExitASM */ |
- | |
314 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_exit00 |
- | |
315 | static int tolua_sjasm_sj_exit00(lua_State* tolua_S) |
- | |
316 | { |
- | |
317 | #ifndef TOLUA_RELEASE |
- | |
318 | tolua_Error tolua_err; |
- | |
319 | if ( |
- | |
320 | !tolua_isnumber(tolua_S,1,1,&tolua_err) || |
- | |
321 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
- | |
322 | ) |
- | |
323 | goto tolua_lerror; |
- | |
324 | else |
- | |
325 | #endif |
- | |
326 | { |
- | |
327 | int p = ((int) tolua_tonumber(tolua_S,1,1)); |
- | |
328 | { |
- | |
329 | ExitASM(p); |
- | |
330 | } |
- | |
331 | } |
- | |
332 | return 0; |
- | |
333 | #ifndef TOLUA_RELEASE |
- | |
334 | tolua_lerror: |
- | |
335 | tolua_error(tolua_S,"#ferror in function 'exit'.",&tolua_err); |
- | |
336 | return 0; |
- | |
337 | #endif |
- | |
338 | } |
- | |
339 | #endif //#ifndef TOLUA_DISABLE |
- | |
340 | 314 | ||
341 | /* function: Error */ |
- | |
342 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_error00 |
- | |
343 | static int tolua_sjasm_sj_error00(lua_State* tolua_S) |
- | |
344 | { |
- | |
345 | #ifndef TOLUA_RELEASE |
- | |
346 | tolua_Error tolua_err; |
- | |
347 | if ( |
- | |
348 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
- | |
349 | !tolua_isstring(tolua_S,2,1,&tolua_err) || |
- | |
350 | !tolua_isnumber(tolua_S,3,1,&tolua_err) || |
- | |
351 | !tolua_isnoobj(tolua_S,4,&tolua_err) |
- | |
352 | ) |
- | |
353 | goto tolua_lerror; |
- | |
354 | else |
- | |
355 | #endif |
- | |
356 | { |
- | |
357 | char* tolua_var_9 = ((char*) tolua_tostring(tolua_S,1,0)); |
- | |
358 | char* tolua_var_10 = ((char*) tolua_tostring(tolua_S,2,0)); |
- | |
359 | EStatus tolua_var_11 = ((EStatus) tolua_tovalue(tolua_S,3,ALL)); |
- | |
360 | { |
- | |
361 | Error(tolua_var_9, tolua_var_10, tolua_var_11); |
- | |
362 | } |
- | |
363 | } |
- | |
364 | return 0; |
- | |
365 | #ifndef TOLUA_RELEASE |
- | |
366 | tolua_lerror: |
- | |
367 | tolua_error(tolua_S,"#ferror in function 'error'.",&tolua_err); |
- | |
368 | return 0; |
- | |
369 | #endif |
- | |
370 | } |
- | |
371 | #endif //#ifndef TOLUA_DISABLE |
- | |
372 | - | ||
373 | /* function: Warning */ |
- | |
374 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_warning00 |
- | |
375 | static int tolua_sjasm_sj_warning00(lua_State* tolua_S) |
- | |
376 | { |
- | |
377 | #ifndef TOLUA_RELEASE |
- | |
378 | tolua_Error tolua_err; |
- | |
379 | if ( |
- | |
380 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
- | |
381 | !tolua_isstring(tolua_S,2,1,&tolua_err) || |
- | |
382 | !tolua_isnumber(tolua_S,3,1,&tolua_err) || |
- | |
383 | !tolua_isnoobj(tolua_S,4,&tolua_err) |
- | |
384 | ) |
- | |
385 | goto tolua_lerror; |
- | |
386 | else |
- | |
387 | #endif |
- | |
388 | { |
- | |
389 | char* tolua_var_12 = ((char*) tolua_tostring(tolua_S,1,0)); |
- | |
390 | char* tolua_var_13 = ((char*) tolua_tostring(tolua_S,2,0)); |
- | |
391 | EWStatus tolua_var_14 = ((EWStatus) tolua_tovalue(tolua_S,3,W_ALL)); |
- | |
392 | { |
- | |
393 | Warning(tolua_var_12, tolua_var_13, tolua_var_14); |
- | |
394 | } |
- | |
395 | } |
- | |
396 | return 0; |
- | |
397 | #ifndef TOLUA_RELEASE |
- | |
398 | tolua_lerror: |
- | |
399 | tolua_error(tolua_S,"#ferror in function 'warning'.",&tolua_err); |
- | |
400 | return 0; |
- | |
401 | #endif |
- | |
402 | } |
- | |
403 | #endif //#ifndef TOLUA_DISABLE |
- | |
404 | - | ||
405 | /* function: FileExists */ |
- | |
406 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_file_exists00 |
- | |
407 | static int tolua_sjasm_sj_file_exists00(lua_State* tolua_S) |
- | |
408 | { |
- | |
409 | #ifndef TOLUA_RELEASE |
- | |
410 | tolua_Error tolua_err; |
- | |
411 | if ( |
- | |
412 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
- | |
413 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
- | |
414 | ) |
- | |
415 | goto tolua_lerror; |
- | |
416 | else |
- | |
417 | #endif |
- | |
418 | { |
- | |
419 | char* filename = ((char*) tolua_tostring(tolua_S,1,0)); |
- | |
420 | { |
- | |
421 | bool tolua_ret = (bool) FileExists(filename); |
- | |
422 | tolua_pushboolean(tolua_S,(bool)tolua_ret); |
- | |
423 | } |
- | |
424 | } |
- | |
425 | return 1; |
- | |
426 | #ifndef TOLUA_RELEASE |
- | |
427 | tolua_lerror: |
- | |
428 | tolua_error(tolua_S,"#ferror in function 'file_exists'.",&tolua_err); |
- | |
429 | return 0; |
- | |
430 | #endif |
- | |
431 | } |
- | |
432 | #endif //#ifndef TOLUA_DISABLE |
- | |
433 | - | ||
434 | /* function: GetPath */ |
- | |
435 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_get_path00 |
- | |
436 | static int tolua_sjasm_sj_get_path00(lua_State* tolua_S) |
- | |
437 | { |
- | |
438 | #ifndef TOLUA_RELEASE |
- | |
439 | tolua_Error tolua_err; |
- | |
440 | if ( |
- | |
441 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
- | |
442 | !tolua_isusertype(tolua_S,2,"TCHAR",0,&tolua_err) || |
- | |
443 | !tolua_isnoobj(tolua_S,3,&tolua_err) |
- | |
444 | ) |
- | |
445 | goto tolua_lerror; |
- | |
446 | else |
- | |
447 | #endif |
- | |
448 | { |
- | |
449 | char* fname = ((char*) tolua_tostring(tolua_S,1,0)); |
- | |
450 | TCHAR* filenamebegin = ((TCHAR*) tolua_tousertype(tolua_S,2,0)); |
- | |
451 | { |
- | |
452 | char* tolua_ret = (char*) GetPath(fname,&filenamebegin); |
- | |
453 | tolua_pushstring(tolua_S,(const char*)tolua_ret); |
- | |
454 | tolua_pushusertype(tolua_S,(void*)filenamebegin,"TCHAR"); |
- | |
455 | } |
- | |
456 | } |
- | |
457 | return 2; |
- | |
458 | #ifndef TOLUA_RELEASE |
- | |
459 | tolua_lerror: |
- | |
460 | tolua_error(tolua_S,"#ferror in function 'get_path'.",&tolua_err); |
- | |
461 | return 0; |
- | |
462 | #endif |
- | |
463 | } |
- | |
464 | #endif //#ifndef TOLUA_DISABLE |
- | |
465 | - | ||
466 | /* function: SetDevice */ |
- | |
467 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_set_device00 |
- | |
468 | static int tolua_sjasm_sj_set_device00(lua_State* tolua_S) |
- | |
469 | { |
- | |
470 | #ifndef TOLUA_RELEASE |
- | |
471 | tolua_Error tolua_err; |
- | |
472 | if ( |
- | |
473 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
- | |
474 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
- | |
475 | ) |
- | |
476 | goto tolua_lerror; |
- | |
477 | else |
- | |
478 | #endif |
- | |
479 | { |
- | |
480 | char* id = ((char*) tolua_tostring(tolua_S,1,0)); |
- | |
481 | { |
- | |
482 | bool tolua_ret = (bool) SetDevice(id); |
- | |
483 | tolua_pushboolean(tolua_S,(bool)tolua_ret); |
- | |
484 | } |
- | |
485 | } |
- | |
486 | return 1; |
- | |
487 | #ifndef TOLUA_RELEASE |
- | |
488 | tolua_lerror: |
- | |
489 | tolua_error(tolua_S,"#ferror in function 'set_device'.",&tolua_err); |
- | |
490 | return 0; |
- | |
491 | #endif |
- | |
492 | } |
- | |
493 | #endif //#ifndef TOLUA_DISABLE |
- | |
494 | - | ||
495 | /* function: GetDeviceName */ |
- | |
496 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_get_device00 |
- | |
497 | static int tolua_sjasm_sj_get_device00(lua_State* tolua_S) |
- | |
498 | { |
- | |
499 | #ifndef TOLUA_RELEASE |
- | |
500 | tolua_Error tolua_err; |
- | |
501 | if ( |
- | |
502 | !tolua_isnoobj(tolua_S,1,&tolua_err) |
- | |
503 | ) |
- | |
504 | goto tolua_lerror; |
- | |
505 | else |
- | |
506 | #endif |
- | |
507 | { |
- | |
508 | { |
- | |
509 | char* tolua_ret = (char*) GetDeviceName(); |
- | |
510 | tolua_pushstring(tolua_S,(const char*)tolua_ret); |
- | |
511 | } |
- | |
512 | } |
- | |
513 | return 1; |
- | |
514 | #ifndef TOLUA_RELEASE |
- | |
515 | tolua_lerror: |
- | |
516 | tolua_error(tolua_S,"#ferror in function 'get_device'.",&tolua_err); |
- | |
517 | return 0; |
- | |
518 | #endif |
- | |
519 | } |
- | |
520 | #endif //#ifndef TOLUA_DISABLE |
- | |
521 | - | ||
522 | /* function: LuaSetPage */ |
- | |
523 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_set_page00 |
- | |
524 | static int tolua_sjasm_sj_set_page00(lua_State* tolua_S) |
- | |
525 | { |
- | |
526 | #ifndef TOLUA_RELEASE |
- | |
527 | tolua_Error tolua_err; |
- | |
528 | if ( |
- | |
529 | !tolua_isnumber(tolua_S,1,0,&tolua_err) || |
- | |
530 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
- | |
531 | ) |
- | |
532 | goto tolua_lerror; |
- | |
533 | else |
- | |
534 | #endif |
- | |
535 | { |
- | |
536 | unsigned int n = ((unsigned int) tolua_tonumber(tolua_S,1,0)); |
- | |
537 | { |
- | |
538 | bool tolua_ret = (bool) LuaSetPage(n); |
- | |
539 | tolua_pushboolean(tolua_S,(bool)tolua_ret); |
- | |
540 | } |
- | |
541 | } |
- | |
542 | return 1; |
- | |
543 | #ifndef TOLUA_RELEASE |
- | |
544 | tolua_lerror: |
- | |
545 | tolua_error(tolua_S,"#ferror in function 'set_page'.",&tolua_err); |
- | |
546 | return 0; |
- | |
547 | #endif |
- | |
548 | } |
- | |
549 | #endif //#ifndef TOLUA_DISABLE |
- | |
550 | - | ||
551 | /* function: LuaSetSlot */ |
- | |
552 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_set_slot00 |
- | |
553 | static int tolua_sjasm_sj_set_slot00(lua_State* tolua_S) |
- | |
554 | { |
- | |
555 | #ifndef TOLUA_RELEASE |
- | |
556 | tolua_Error tolua_err; |
- | |
557 | if ( |
- | |
558 | !tolua_isnumber(tolua_S,1,0,&tolua_err) || |
- | |
559 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
- | |
560 | ) |
- | |
561 | goto tolua_lerror; |
- | |
562 | else |
- | |
563 | #endif |
- | |
564 | { |
- | |
565 | unsigned int n = ((unsigned int) tolua_tonumber(tolua_S,1,0)); |
- | |
566 | { |
- | |
567 | bool tolua_ret = (bool) LuaSetSlot(n); |
- | |
568 | tolua_pushboolean(tolua_S,(bool)tolua_ret); |
- | |
569 | } |
- | |
570 | } |
- | |
571 | return 1; |
- | |
572 | #ifndef TOLUA_RELEASE |
- | |
573 | tolua_lerror: |
- | |
574 | tolua_error(tolua_S,"#ferror in function 'set_slot'.",&tolua_err); |
- | |
575 | return 0; |
- | |
576 | #endif |
- | |
577 | } |
- | |
578 | #endif //#ifndef TOLUA_DISABLE |
- | |
579 | - | ||
580 | /* function: MemGetByte */ |
- | |
581 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_get_byte00 |
- | |
582 | static int tolua_sjasm_sj_get_byte00(lua_State* tolua_S) |
- | |
583 | { |
- | |
584 | #ifndef TOLUA_RELEASE |
- | |
585 | tolua_Error tolua_err; |
- | |
586 | if ( |
- | |
587 | !tolua_isnumber(tolua_S,1,0,&tolua_err) || |
- | |
588 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
- | |
589 | ) |
- | |
590 | goto tolua_lerror; |
- | |
591 | else |
- | |
592 | #endif |
- | |
593 | { |
- | |
594 | unsigned int address = ((unsigned int) tolua_tonumber(tolua_S,1,0)); |
- | |
595 | { |
- | |
596 | unsigned char tolua_ret = (unsigned char) MemGetByte(address); |
- | |
597 | tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); |
- | |
598 | } |
- | |
599 | } |
- | |
600 | return 1; |
- | |
601 | #ifndef TOLUA_RELEASE |
- | |
602 | tolua_lerror: |
- | |
603 | tolua_error(tolua_S,"#ferror in function 'get_byte'.",&tolua_err); |
- | |
604 | return 0; |
- | |
605 | #endif |
- | |
606 | } |
- | |
607 | #endif //#ifndef TOLUA_DISABLE |
- | |
608 | - | ||
609 | /* function: MemGetWord */ |
- | |
610 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_get_word00 |
- | |
611 | static int tolua_sjasm_sj_get_word00(lua_State* tolua_S) |
- | |
612 | { |
- | |
613 | #ifndef TOLUA_RELEASE |
- | |
614 | tolua_Error tolua_err; |
- | |
615 | if ( |
- | |
616 | !tolua_isnumber(tolua_S,1,0,&tolua_err) || |
- | |
617 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
- | |
618 | ) |
- | |
619 | goto tolua_lerror; |
- | |
620 | else |
- | |
621 | #endif |
- | |
622 | { |
- | |
623 | unsigned int address = ((unsigned int) tolua_tonumber(tolua_S,1,0)); |
- | |
624 | { |
- | |
625 | lua_Number tolua_ret = 0xFFFF & MemGetWord(address); |
- | |
626 | tolua_pushnumber(tolua_S, tolua_ret); |
- | |
627 | } |
- | |
628 | } |
- | |
629 | return 1; |
- | |
630 | #ifndef TOLUA_RELEASE |
- | |
631 | tolua_lerror: |
- | |
632 | tolua_error(tolua_S,"#ferror in function 'get_word'.",&tolua_err); |
- | |
633 | return 0; |
- | |
634 | #endif |
- | |
635 | } |
- | |
636 | #endif //#ifndef TOLUA_DISABLE |
- | |
637 | - | ||
638 | /* function: EmitByte */ |
- | |
639 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_add_byte00 |
- | |
640 | static int tolua_sjasm_sj_add_byte00(lua_State* tolua_S) |
315 | static void lua_sj_add_byte(int byte) { |
641 | { |
- | |
642 | #ifndef TOLUA_RELEASE |
- | |
643 | tolua_Error tolua_err; |
- | |
644 | if ( |
- | |
645 | !tolua_isnumber(tolua_S,1,0,&tolua_err) || |
- | |
646 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
- | |
647 | ) |
- | |
648 | goto tolua_lerror; |
- | |
649 | else |
- | |
650 | #endif |
- | |
651 | { |
- | |
652 | unsigned char byte = ((unsigned char) tolua_tonumber(tolua_S,1,0)); |
316 | int positionsAdded = addLuaSourcePositions(); // add known script positions to sourcePosStack vector |
653 | { |
- | |
654 | EmitByte(byte); |
317 | EmitByte(byte); |
- | 318 | removeLuaSourcePositions(positionsAdded); |
|
655 | } |
319 | } |
656 | } |
- | |
657 | return 0; |
- | |
658 | #ifndef TOLUA_RELEASE |
- | |
659 | tolua_lerror: |
- | |
660 | tolua_error(tolua_S,"#ferror in function 'add_byte'.",&tolua_err); |
- | |
661 | return 0; |
- | |
662 | #endif |
- | |
663 | } |
- | |
664 | #endif //#ifndef TOLUA_DISABLE |
- | |
665 | 320 | ||
666 | /* function: EmitWord */ |
- | |
667 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_add_word00 |
- | |
668 | static int tolua_sjasm_sj_add_word00(lua_State* tolua_S) |
321 | static void lua_sj_add_word(int word) { |
669 | { |
- | |
670 | #ifndef TOLUA_RELEASE |
- | |
671 | tolua_Error tolua_err; |
- | |
672 | if ( |
- | |
673 | !tolua_isnumber(tolua_S,1,0,&tolua_err) || |
- | |
674 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
- | |
675 | ) |
- | |
676 | goto tolua_lerror; |
- | |
677 | else |
- | |
678 | #endif |
- | |
679 | { |
- | |
680 | unsigned int word = ((unsigned int) tolua_tonumber(tolua_S,1,0)); |
322 | int positionsAdded = addLuaSourcePositions(); // add known script positions to sourcePosStack vector |
681 | { |
- | |
682 | EmitWord(word); |
323 | EmitWord(word); |
- | 324 | removeLuaSourcePositions(positionsAdded); |
|
683 | } |
325 | } |
- | 326 | ||
- | 327 | static unsigned char lua_sj_get_byte(unsigned int address) { |
|
- | 328 | int positionsAdded = addLuaSourcePositions(); // add known script positions to sourcePosStack vector |
|
- | 329 | auto result = MemGetByte(address); |
|
- | 330 | removeLuaSourcePositions(positionsAdded); |
|
- | 331 | return result; |
|
- | 332 | } |
|
- | 333 | ||
- | 334 | static unsigned int lua_sj_get_word(unsigned int address) { |
|
- | 335 | int positionsAdded = addLuaSourcePositions(); // add known script positions to sourcePosStack vector |
|
- | 336 | auto result = MemGetWord(address); |
|
- | 337 | removeLuaSourcePositions(positionsAdded); |
|
- | 338 | return result; |
|
- | 339 | } |
|
- | 340 | ||
- | 341 | static bool lua_zx_trdimage_create(const char* trdname, const char* label = nullptr) { |
|
- | 342 | // setup label to truncated 8 char array padded with spaces |
|
- | 343 | char l8[9] = " "; |
|
- | 344 | char* l8_ptr = l8; |
|
- | 345 | while (label && *label && (l8_ptr - l8) < 8) *l8_ptr++ = *label++; |
|
- | 346 | int positionsAdded = addLuaSourcePositions(); // add known script positions to sourcePosStack vector |
|
- | 347 | bool result = TRD_SaveEmpty(trdname, l8); |
|
- | 348 | removeLuaSourcePositions(positionsAdded); |
|
- | 349 | return result; |
|
- | 350 | } |
|
- | 351 | ||
- | 352 | bool lua_zx_trdimage_add_file(const char* trd, const char* file, int start, int length, int autostart = -1, bool replace = false) { |
|
- | 353 | int positionsAdded = addLuaSourcePositions(); // add known script positions to sourcePosStack vector |
|
- | 354 | bool result = nullptr != trd && nullptr != file && TRD_AddFile(trd, file, start, length, autostart, replace, false); |
|
- | 355 | removeLuaSourcePositions(positionsAdded); |
|
- | 356 | return result; |
|
- | 357 | } |
|
- | 358 | ||
- | 359 | static bool lua_zx_save_snapshot_sna(const char* fname, word start) { |
|
- | 360 | int positionsAdded = addLuaSourcePositions(); // add known script positions to sourcePosStack vector |
|
- | 361 | bool result = SaveSNA_ZX(fname, start); |
|
- | 362 | removeLuaSourcePositions(positionsAdded); |
|
- | 363 | return result; |
|
- | 364 | } |
|
- | 365 | ||
- | 366 | static void lua_impl_init() { |
|
- | 367 | assert(nullptr == LUA); |
|
- | 368 | ||
- | 369 | scripts_origin.reserve(64); |
|
- | 370 | ||
- | 371 | // initialise Lua (regular Lua, without sjasmplus bindings/extensions) |
|
- | 372 | LUA = luaL_newstate(); |
|
- | 373 | lua_atpanic(LUA, (lua_CFunction)lua_impl_fatalError); |
|
- | 374 | ||
- | 375 | // for manual testing of lua_atpanic handler |
|
- | 376 | // { lua_error(LUA); } |
|
- | 377 | // { lua_pushstring(LUA, "testing at panic handler"); lua_error(LUA); } |
|
- | 378 | ||
- | 379 | luaL_openlibs(LUA); |
|
- | 380 | ||
- | 381 | // initialise sjasmplus bindings/extensions |
|
- | 382 | luabridge::getGlobalNamespace(LUA) |
|
- | 383 | .addFunction("_c", lua_sj_calc) |
|
- | 384 | .addFunction("_pl", lua_sj_parse_line) |
|
- | 385 | .addFunction("_pc", lua_sj_parse_code) |
|
- | 386 | .beginNamespace("sj") |
|
- | 387 | .addProperty("current_address", &CurAddress, false) // read-only |
|
- | 388 | .addProperty("warning_count", &WarningCount, false) // read-only |
|
- | 389 | .addProperty("error_count", &ErrorCount, false) // read-only |
|
- | 390 | // internal functions which are lua-wrapped to enable optional arguments |
|
- | 391 | .addFunction("error_i", lua_sj_error) |
|
- | 392 | .addFunction("warning_i", lua_sj_warning) |
|
- | 393 | .addFunction("insert_define_i", lua_sj_insert_define) |
|
- | 394 | .addFunction("exit_i", ExitASM) |
|
- | 395 | .addFunction("set_device_i", lua_sj_set_device) |
|
- | 396 | // remaining public functions with all arguments mandatory (boolean args seems to default to false?) |
|
- | 397 | .addFunction("get_define", lua_sj_get_define) |
|
- | 398 | .addFunction("get_label", lua_sj_get_label) |
|
- | 399 | .addFunction("insert_label", lua_sj_insert_label) |
|
- | 400 | .addFunction("shellexec", lua_sj_shellexec) |
|
- | 401 | .addFunction("calc", lua_sj_calc) |
|
- | 402 | .addFunction("parse_line", lua_sj_parse_line) |
|
- | 403 | .addFunction("parse_code", lua_sj_parse_code) |
|
- | 404 | .addFunction("add_byte", lua_sj_add_byte) |
|
- | 405 | .addFunction("add_word", lua_sj_add_word) |
|
- | 406 | .addFunction("get_byte", lua_sj_get_byte) |
|
- | 407 | .addFunction("get_word", lua_sj_get_word) |
|
- | 408 | .addFunction("get_device", GetDeviceName) // no error/warning, can be called directly |
|
- | 409 | .addFunction("set_page", lua_sj_set_page) |
|
- | 410 | .addFunction("set_slot", lua_sj_set_slot) |
|
- | 411 | // MMU API will be not added, it is too dynamic, and _pc("MMU ...") works |
|
- | 412 | .addFunction("file_exists", FileExists) |
|
- | 413 | .endNamespace() |
|
- | 414 | .beginNamespace("zx") |
|
- | 415 | .addFunction("trdimage_create_i", lua_zx_trdimage_create) |
|
- | 416 | .addFunction("trdimage_add_file_i", lua_zx_trdimage_add_file) |
|
- | 417 | .addFunction("save_snapshot_sna", lua_zx_save_snapshot_sna) |
|
- | 418 | .endNamespace(); |
|
- | 419 | ||
- | 420 | TextFilePos binding_script_pos(binding_script_name, binding_script_line); |
|
- | 421 | if (luaL_loadbuffer(LUA, lua_impl_init_bindings_script.c_str(), lua_impl_init_bindings_script.size(), lua_impl_get_script_name(binding_script_pos)) |
|
- | 422 | || lua_pcall(LUA, 0, LUA_MULTRET, 0)) { |
|
- | 423 | lua_impl_showLoadError(FATAL); // unreachable (I hope) // manual testing: damage binding script |
|
- | 424 | } |
|
- | 425 | } |
|
- | 426 | ||
- | 427 | void dirENDLUA() { |
|
- | 428 | Error("[ENDLUA] End of lua script without script"); |
|
- | 429 | } |
|
- | 430 | ||
- | 431 | void dirLUA() { |
|
- | 432 | // lazy init of Lua scripting upon first hit of LUA directive |
|
- | 433 | if (nullptr == LUA) lua_impl_init(); |
|
- | 434 | assert(LUA); |
|
- | 435 | ||
- | 436 | constexpr size_t luaBufferSize = 32768; |
|
- | 437 | char* id, * buff = nullptr, * bp = nullptr; |
|
- | 438 | ||
- | 439 | int passToExec = LASTPASS; |
|
- | 440 | if ((id = GetID(lp)) && strlen(id) > 0) { |
|
- | 441 | if (cmphstr(id, "pass1")) { |
|
- | 442 | passToExec = 1; |
|
- | 443 | } else if (cmphstr(id, "pass2")) { |
|
- | 444 | passToExec = 2; |
|
- | 445 | } else if (cmphstr(id, "pass3")) { |
|
- | 446 | passToExec = LASTPASS; |
|
- | 447 | } else if (cmphstr(id, "allpass")) { |
|
- | 448 | passToExec = -1; |
|
- | 449 | } else { |
|
- | 450 | Error("[LUA] Syntax error", id); |
|
- | 451 | } |
|
- | 452 | } |
|
- | 453 | ||
- | 454 | const EStatus errorType = (1 == passToExec || 2 == passToExec) ? EARLY : PASS3; |
|
- | 455 | const bool execute = (-1 == passToExec) || (passToExec == pass); |
|
- | 456 | // remember warning suppression also from block start |
|
- | 457 | bool showWarning = !suppressedById(W_LUA_MC_PASS); |
|
- | 458 | ||
- | 459 | assert(!sourcePosStack.empty()); |
|
- | 460 | TextFilePos luaStartPos = sourcePosStack.back(); // position of LUA directive (not ENDLUA) |
|
- | 461 | if (execute) { |
|
- | 462 | buff = new char[luaBufferSize]; |
|
- | 463 | bp = buff; |
|
- | 464 | } |
|
- | 465 | ListFile(); |
|
- | 466 | ||
- | 467 | while (1) { |
|
- | 468 | if (!ReadLine(false)) { |
|
- | 469 | Error("[LUA] Unexpected end of lua script"); |
|
- | 470 | break; |
|
- | 471 | } |
|
- | 472 | lp = line; |
|
- | 473 | SkipBlanks(lp); |
|
- | 474 | const int isEndLua = cmphstr(lp, "endlua"); |
|
- | 475 | const size_t lineLen = isEndLua ? (lp - 6 - line) : strlen(line); |
|
- | 476 | if (execute) { |
|
- | 477 | if (luaBufferSize < (bp - buff) + lineLen + 4) { |
|
- | 478 | ErrorInt("[LUA] Maximum byte-size of Lua script is", luaBufferSize-4, FATAL); |
|
- | 479 | } |
|
- | 480 | memcpy(bp, line, lineLen); |
|
- | 481 | bp += lineLen; |
|
- | 482 | *bp++ = '\n'; |
|
- | 483 | } |
|
- | 484 | if (isEndLua) { // eat also any trailing eol-type of comment |
|
- | 485 | skipEmitMessagePos = sourcePosStack.back(); |
|
- | 486 | ++CompiledCurrentLine; |
|
- | 487 | lp = ReplaceDefine(lp); // skip any empty substitutions and comments |
|
- | 488 | substitutedLine = line; // override substituted listing for ENDLUA |
|
- | 489 | // take into account also warning suppression used at end of block |
|
- | 490 | showWarning = showWarning && !suppressedById(W_LUA_MC_PASS); |
|
- | 491 | break; |
|
- | 492 | } |
|
- | 493 | ListFile(true); |
|
- | 494 | } |
|
- | 495 | ||
- | 496 | if (execute) { |
|
- | 497 | extraErrorWarningPrefix = lua_err_prefix; |
|
- | 498 | *bp = 0; |
|
- | 499 | DidEmitByte(); // reset the flag before running lua script |
|
- | 500 | if (luaL_loadbuffer(LUA, buff, bp-buff, lua_impl_get_script_name(luaStartPos)) || lua_pcall(LUA, 0, LUA_MULTRET, 0)) { |
|
- | 501 | lua_impl_showLoadError(errorType); |
|
- | 502 | } |
|
- | 503 | extraErrorWarningPrefix = nullptr; |
|
- | 504 | delete[] buff; |
|
- | 505 | if (DidEmitByte() && (-1 != passToExec) && showWarning) { |
|
- | 506 | const EWStatus warningType = (1 == passToExec || 2 == passToExec) ? W_EARLY : W_PASS3; |
|
- | 507 | WarningById(W_LUA_MC_PASS, nullptr, warningType); |
|
- | 508 | } |
|
- | 509 | } |
|
- | 510 | ||
- | 511 | ++CompiledCurrentLine; |
|
- | 512 | substitutedLine = line; // override substituted list line for ENDLUA |
|
- | 513 | } |
|
- | 514 | ||
- | 515 | void dirINCLUDELUA() { |
|
- | 516 | // lazy init of Lua scripting upon first hit of INCLUDELUA directive |
|
- | 517 | if (nullptr == LUA) lua_impl_init(); |
|
- | 518 | assert(LUA); |
|
- | 519 | ||
- | 520 | if (1 != pass) { |
|
- | 521 | SkipToEol(lp); // skip till EOL (colon), to avoid parsing file name |
|
- | 522 | return; |
|
- | 523 | } |
|
- | 524 | std::unique_ptr<char[]> fnaam(GetFileName(lp)); |
|
- | 525 | EDelimiterType dt = GetDelimiterOfLastFileName(); |
|
- | 526 | char* fullpath = GetPath(fnaam.get(), NULL, DT_ANGLE == dt); |
|
- | 527 | if (!fullpath[0]) { |
|
- | 528 | Error("[INCLUDELUA] File doesn't exist", fnaam.get(), EARLY); |
|
- | 529 | } else { |
|
- | 530 | extraErrorWarningPrefix = lua_err_prefix; |
|
- | 531 | fileNameFull = ArchiveFilename(fullpath); // get const pointer into archive |
|
- | 532 | if (luaL_dofile(LUA, fileNameFull)) { |
|
- | 533 | lua_impl_showLoadError(EARLY); |
|
- | 534 | } |
|
- | 535 | extraErrorWarningPrefix = nullptr; |
|
- | 536 | } |
|
- | 537 | free(fullpath); |
|
- | 538 | } |
|
- | 539 | ||
- | 540 | #endif //USE_LUA |
|
- | 541 | ||
- | 542 | //////////////////////////////////////////////////////////////////////////////////////////// |
|
- | 543 | // close LUA engine and release everything related |
|
- | 544 | void lua_impl_close() { |
|
- | 545 | #ifdef USE_LUA |
|
- | 546 | // if Lua was used and initialised, release everything |
|
- | 547 | if (LUA) lua_close(LUA); |
|
- | 548 | #endif //USE_LUA |
|
- | 549 | ||
- | 550 | // do nothing when Lua is compile-time disabled |
|
684 | } |
551 | } |
685 | return 0; |
- | |
686 | #ifndef TOLUA_RELEASE |
- | |
687 | tolua_lerror: |
- | |
688 | tolua_error(tolua_S,"#ferror in function 'add_word'.",&tolua_err); |
- | |
689 | return 0; |
- | |
690 | #endif |
- | |
691 | } |
- | |
692 | #endif //#ifndef TOLUA_DISABLE |
- | |
693 | - | ||
694 | /* function: LuaCalculate */ |
- | |
695 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_calc00 |
- | |
696 | static int tolua_sjasm_sj_calc00(lua_State* tolua_S) |
- | |
697 | { |
- | |
698 | #ifndef TOLUA_RELEASE |
- | |
699 | tolua_Error tolua_err; |
- | |
700 | if ( |
- | |
701 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
- | |
702 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
- | |
703 | ) |
- | |
704 | goto tolua_lerror; |
- | |
705 | else |
- | |
706 | #endif |
- | |
707 | { |
- | |
708 | char* str = ((char*) tolua_tostring(tolua_S,1,0)); |
- | |
709 | { |
- | |
710 | lua_Number tolua_ret = LuaCalculate(str); |
- | |
711 | tolua_pushnumber(tolua_S, tolua_ret); |
- | |
712 | } |
- | |
713 | } |
- | |
714 | return 1; |
- | |
715 | #ifndef TOLUA_RELEASE |
- | |
716 | tolua_lerror: |
- | |
717 | tolua_error(tolua_S,"#ferror in function 'calc'.",&tolua_err); |
- | |
718 | return 0; |
- | |
719 | #endif |
- | |
720 | } |
- | |
721 | #endif //#ifndef TOLUA_DISABLE |
- | |
722 | - | ||
723 | /* function: LuaParseLine */ |
- | |
724 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_parse_line00 |
- | |
725 | static int tolua_sjasm_sj_parse_line00(lua_State* tolua_S) |
- | |
726 | { |
- | |
727 | #ifndef TOLUA_RELEASE |
- | |
728 | tolua_Error tolua_err; |
- | |
729 | if ( |
- | |
730 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
- | |
731 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
- | |
732 | ) |
- | |
733 | goto tolua_lerror; |
- | |
734 | else |
- | |
735 | #endif |
- | |
736 | { |
- | |
737 | char* str = ((char*) tolua_tostring(tolua_S,1,0)); |
- | |
738 | { |
- | |
739 | LuaParseLine(str); |
- | |
740 | } |
- | |
741 | } |
- | |
742 | return 0; |
- | |
743 | #ifndef TOLUA_RELEASE |
- | |
744 | tolua_lerror: |
- | |
745 | tolua_error(tolua_S,"#ferror in function 'parse_line'.",&tolua_err); |
- | |
746 | return 0; |
- | |
747 | #endif |
- | |
748 | } |
- | |
749 | #endif //#ifndef TOLUA_DISABLE |
- | |
750 | - | ||
751 | /* function: LuaParseCode */ |
- | |
752 | #ifndef TOLUA_DISABLE_tolua_sjasm_sj_parse_code00 |
- | |
753 | static int tolua_sjasm_sj_parse_code00(lua_State* tolua_S) |
- | |
754 | { |
- | |
755 | #ifndef TOLUA_RELEASE |
- | |
756 | tolua_Error tolua_err; |
- | |
757 | if ( |
- | |
758 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
- | |
759 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
- | |
760 | ) |
- | |
761 | goto tolua_lerror; |
- | |
762 | else |
- | |
763 | #endif |
- | |
764 | { |
- | |
765 | char* str = ((char*) tolua_tostring(tolua_S,1,0)); |
- | |
766 | { |
- | |
767 | LuaParseCode(str); |
- | |
768 | } |
- | |
769 | } |
- | |
770 | return 0; |
- | |
771 | #ifndef TOLUA_RELEASE |
- | |
772 | tolua_lerror: |
- | |
773 | tolua_error(tolua_S,"#ferror in function 'parse_code'.",&tolua_err); |
- | |
774 | return 0; |
- | |
775 | #endif |
- | |
776 | } |
- | |
777 | #endif //#ifndef TOLUA_DISABLE |
- | |
778 | - | ||
779 | /* function: LuaCalculate */ |
- | |
780 | #ifndef TOLUA_DISABLE_tolua_sjasm__c00 |
- | |
781 | static int tolua_sjasm__c00(lua_State* tolua_S) |
- | |
782 | { |
- | |
783 | #ifndef TOLUA_RELEASE |
- | |
784 | tolua_Error tolua_err; |
- | |
785 | if ( |
- | |
786 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
- | |
787 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
- | |
788 | ) |
- | |
789 | goto tolua_lerror; |
- | |
790 | else |
- | |
791 | #endif |
- | |
792 | { |
- | |
793 | char* str = ((char*) tolua_tostring(tolua_S,1,0)); |
- | |
794 | { |
- | |
795 | lua_Number tolua_ret = LuaCalculate(str); |
- | |
796 | tolua_pushnumber(tolua_S, tolua_ret); |
- | |
797 | } |
- | |
798 | } |
- | |
799 | return 1; |
- | |
800 | #ifndef TOLUA_RELEASE |
- | |
801 | tolua_lerror: |
- | |
802 | tolua_error(tolua_S,"#ferror in function '_c'.",&tolua_err); |
- | |
803 | return 0; |
- | |
804 | #endif |
- | |
805 | } |
- | |
806 | #endif //#ifndef TOLUA_DISABLE |
- | |
807 | - | ||
808 | /* function: LuaParseLine */ |
- | |
809 | #ifndef TOLUA_DISABLE_tolua_sjasm__pl00 |
- | |
810 | static int tolua_sjasm__pl00(lua_State* tolua_S) |
- | |
811 | { |
- | |
812 | #ifndef TOLUA_RELEASE |
- | |
813 | tolua_Error tolua_err; |
- | |
814 | if ( |
- | |
815 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
- | |
816 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
- | |
817 | ) |
- | |
818 | goto tolua_lerror; |
- | |
819 | else |
- | |
820 | #endif |
- | |
821 | { |
- | |
822 | char* str = ((char*) tolua_tostring(tolua_S,1,0)); |
- | |
823 | { |
- | |
824 | LuaParseLine(str); |
- | |
825 | } |
- | |
826 | } |
- | |
827 | return 0; |
- | |
828 | #ifndef TOLUA_RELEASE |
- | |
829 | tolua_lerror: |
- | |
830 | tolua_error(tolua_S,"#ferror in function '_pl'.",&tolua_err); |
- | |
831 | return 0; |
- | |
832 | #endif |
- | |
833 | } |
- | |
834 | #endif //#ifndef TOLUA_DISABLE |
- | |
835 | - | ||
836 | /* function: LuaParseCode */ |
- | |
837 | #ifndef TOLUA_DISABLE_tolua_sjasm__pc00 |
- | |
838 | static int tolua_sjasm__pc00(lua_State* tolua_S) |
- | |
839 | { |
- | |
840 | #ifndef TOLUA_RELEASE |
- | |
841 | tolua_Error tolua_err; |
- | |
842 | if ( |
- | |
843 | !tolua_isstring(tolua_S,1,0,&tolua_err) || |
- | |
844 | !tolua_isnoobj(tolua_S,2,&tolua_err) |
- | |
845 | ) |
- | |
846 | goto tolua_lerror; |
- | |
847 | else |
- | |
848 | #endif |
- | |
849 | { |
- | |
850 | char* str = ((char*) tolua_tostring(tolua_S,1,0)); |
- | |
851 | { |
- | |
852 | LuaParseCode(str); |
- | |
853 | } |
- | |
854 | } |
- | |
855 | return 0; |
- | |
856 | #ifndef TOLUA_RELEASE |
- | |
857 | tolua_lerror: |
- | |
858 | tolua_error(tolua_S,"#ferror in function '_pc'.",&tolua_err); |
- | |
859 | return 0; |
- | |
860 | #endif |
- | |
861 | } |
- | |
862 | #endif //#ifndef TOLUA_DISABLE |
- | |
863 | - | ||
864 | /* Open function */ |
- | |
865 | TOLUA_API int tolua_sjasm_open (lua_State* tolua_S) |
- | |
866 | { |
- | |
867 | tolua_open(tolua_S); |
- | |
868 | tolua_reg_types(tolua_S); |
- | |
869 | tolua_module(tolua_S,NULL,0); |
- | |
870 | tolua_beginmodule(tolua_S,NULL); |
- | |
871 | tolua_module(tolua_S,"sj",0); |
- | |
872 | tolua_beginmodule(tolua_S,"sj"); |
- | |
873 | tolua_function(tolua_S,"get_define",tolua_sjasm_sj_get_define00); |
- | |
874 | tolua_function(tolua_S,"insert_define",tolua_sjasm_sj_insert_define00); |
- | |
875 | tolua_function(tolua_S,"get_label",tolua_sjasm_sj_get_label00); |
- | |
876 | tolua_function(tolua_S,"insert_label",tolua_sjasm_sj_insert_label00); |
- | |
877 | tolua_endmodule(tolua_S); |
- | |
878 | tolua_module(tolua_S,"sj",1); |
- | |
879 | tolua_beginmodule(tolua_S,"sj"); |
- | |
880 | tolua_variable(tolua_S,"current_address",tolua_get_sj_unsigned_current_address,NULL); |
- | |
881 | tolua_variable(tolua_S,"warning_count",tolua_get_sj_warning_count,NULL); |
- | |
882 | tolua_variable(tolua_S,"error_count",tolua_get_sj_error_count,NULL); |
- | |
883 | tolua_function(tolua_S,"shellexec",tolua_sjasm_sj_shellexec00); |
- | |
884 | tolua_endmodule(tolua_S); |
- | |
885 | tolua_module(tolua_S,"zx",0); |
- | |
886 | tolua_beginmodule(tolua_S,"zx"); |
- | |
887 | tolua_function(tolua_S,"trdimage_create",tolua_sjasm_zx_trdimage_create00); |
- | |
888 | tolua_function(tolua_S,"trdimage_add_file",tolua_sjasm_zx_trdimage_add_file00); |
- | |
889 | tolua_function(tolua_S,"save_snapshot_sna128",tolua_sjasm_zx_save_snapshot_sna12800); |
- | |
890 | tolua_endmodule(tolua_S); |
- | |
891 | tolua_module(tolua_S,"sj",1); |
- | |
892 | tolua_beginmodule(tolua_S,"sj"); |
- | |
893 | tolua_variable(tolua_S,"current_path",tolua_get_sj_current_path,NULL); |
- | |
894 | tolua_function(tolua_S,"exit",tolua_sjasm_sj_exit00); |
- | |
895 | tolua_endmodule(tolua_S); |
- | |
896 | tolua_module(tolua_S,"sj",0); |
- | |
897 | tolua_beginmodule(tolua_S,"sj"); |
- | |
898 | tolua_function(tolua_S,"error",tolua_sjasm_sj_error00); |
- | |
899 | tolua_function(tolua_S,"warning",tolua_sjasm_sj_warning00); |
- | |
900 | tolua_function(tolua_S,"file_exists",tolua_sjasm_sj_file_exists00); |
- | |
901 | tolua_function(tolua_S,"get_path",tolua_sjasm_sj_get_path00); |
- | |
902 | tolua_function(tolua_S,"set_device",tolua_sjasm_sj_set_device00); |
- | |
903 | tolua_function(tolua_S,"get_device",tolua_sjasm_sj_get_device00); |
- | |
904 | tolua_function(tolua_S,"set_page",tolua_sjasm_sj_set_page00); |
- | |
905 | tolua_function(tolua_S,"set_slot",tolua_sjasm_sj_set_slot00); |
- | |
906 | tolua_function(tolua_S,"get_byte",tolua_sjasm_sj_get_byte00); |
- | |
907 | tolua_function(tolua_S,"get_word",tolua_sjasm_sj_get_word00); |
- | |
908 | tolua_function(tolua_S,"add_byte",tolua_sjasm_sj_add_byte00); |
- | |
909 | tolua_function(tolua_S,"add_word",tolua_sjasm_sj_add_word00); |
- | |
910 | tolua_function(tolua_S,"calc",tolua_sjasm_sj_calc00); |
- | |
911 | tolua_function(tolua_S,"parse_line",tolua_sjasm_sj_parse_line00); |
- | |
912 | tolua_function(tolua_S,"parse_code",tolua_sjasm_sj_parse_code00); |
- | |
913 | tolua_endmodule(tolua_S); |
- | |
914 | tolua_function(tolua_S,"_c",tolua_sjasm__c00); |
- | |
915 | tolua_function(tolua_S,"_pl",tolua_sjasm__pl00); |
- | |
916 | tolua_function(tolua_S,"_pc",tolua_sjasm__pc00); |
- | |
917 | - | ||
918 | { /* begin embedded lua code */"tolua: embedded Lua code 1"); |
- | |
919 | lua_settop(tolua_S, top); |
- | |
920 | } /* end of embedded lua code */ |
- | |
921 | - | ||
922 | - | ||
923 | { /* begin embedded lua code */ |
- | |
924 | int top = lua_gettop(tolua_S); |
- | |
925 | static unsigned char B[] = { |
- | |
926 | 10, 72,101,120, 32,118, 48, 46, 51, 10, 72,101,120, 32, 99, |
- | |
927 | 111,110,118,101,114,115,105,111,110, 32,108,105, 98, 32,102, |
- | |
928 | 111,114, 32,108,117, 97, 46, 10, 80, 97,114,116, 32,111,102, |
- | |
929 | 32, 76,117, 97, 66,105,116, 40,104,116,116,112, 58, 47, 47, |
- | |
930 | 108,117, 97,102,111,114,103,101, 46,110,101,116, 47,112,114, |
- | |
931 | 111,106,101, 99,116,115, 47, 98,105,116, 47, 41, 46, 10, 85, |
- | |
932 | 110,100,101,114, 32,116,104,101, 32, 77, 73, 84, 32,108,105, |
- | |
933 | 99,101,110,115,101, 46, 10, 99,111,112,121,114,105,103,104, |
- | |
934 | 116, 40, 99, 41, 32, 50, 48, 48, 54, 32,104, 97,110,122,104, |
- | |
935 | 97,111, 32, 40, 97, 98,114, 97,115,104, 95,104, 97,110, 64, |
- | |
936 | 104,111,116,109, 97,105,108, 46, 99,111,109, 41, 10,100,111, |
- | |
937 | 10,108,111, 99, 97,108, 32,102,117,110, 99,116,105,111,110, |
- | |
938 | 32,116,111, 95,104,101,120, 40,110, 41, 10,105,102, 40,116, |
- | |
939 | 121,112,101, 40,110, 41, 32,126, 61, 32, 34,110,117,109, 98, |
- | |
940 | 101,114, 34, 41, 32,116,104,101,110, 10,101,114,114,111,114, |
- | |
941 | 40, 34,110,111,110, 45,110,117,109, 98,101,114, 32,116,121, |
- | |
942 | 112,101, 32,112, 97,115,115,101,100, 32,105,110, 46, 34, 41, |
- | |
943 | 10,101,110,100, 10,105,102, 40,110, 32, 45, 32,109, 97,116, |
- | |
944 | 104, 46,102,108,111,111,114, 40,110, 41, 32, 62, 32, 48, 41, |
- | |
945 | 32,116,104,101,110, 10,101,114,114,111,114, 40, 34,116,114, |
- | |
946 | 121,105,110,103, 32,116,111, 32, 97,112,112,108,121, 32, 98, |
- | |
947 | 105,116,119,105,115,101, 32,111,112,101,114, 97,116,105,111, |
- | |
948 | 110, 32,111,110, 32,110,111,110, 45,105,110,116,101,103,101, |
- | |
949 | 114, 33, 34, 41, 10,101,110,100, 10,105,102, 40,110, 32, 60, |
- | |
950 | 32, 48, 41, 32,116,104,101,110, 10,110, 32, 61, 32, 98,105, |
- | |
951 | 116, 46,116,111, 98,105,116,115, 40, 98,105,116, 46, 98,110, |
- | |
952 | 111,116, 40,109, 97,116,104, 46, 97, 98,115, 40,110, 41, 41, |
- | |
953 | 32, 43, 32, 49, 41, 10,110, 32, 61, 32, 98,105,116, 46,116, |
- | |
954 | 111,110,117,109, 98, 40,110, 41, 10,101,110,100, 10,104,101, |
- | |
955 | 120, 95,116, 98,108, 32, 61, 32,123, 39, 65, 39, 44, 32, 39, |
- | |
956 | 66, 39, 44, 32, 39, 67, 39, 44, 32, 39, 68, 39, 44, 32, 39, |
- | |
957 | 69, 39, 44, 32, 39, 70, 39,125, 10,104,101,120, 95,115,116, |
- | |
958 | 114, 32, 61, 32, 34, 34, 10,119,104,105,108,101, 40,110, 32, |
- | |
959 | 126, 61, 32, 48, 41, 32,100,111, 10,108, 97,115,116, 32, 61, |
- | |
960 | 32,109, 97,116,104, 46,109,111,100, 40,110, 44, 32, 49, 54, |
- | |
961 | 41, 10,105,102, 40,108, 97,115,116, 32, 60, 32, 49, 48, 41, |
- | |
962 | 32,116,104,101,110, 10,104,101,120, 95,115,116,114, 32, 61, |
- | |
963 | 32,116,111,115,116,114,105,110,103, 40,108, 97,115,116, 41, |
- | |
964 | 32, 46, 46, 32,104,101,120, 95,115,116,114, 10,101,108,115, |
- | |
965 | 101, 10,104,101,120, 95,115,116,114, 32, 61, 32,104,101,120, |
- | |
966 | 95,116, 98,108, 91,108, 97,115,116, 45, 49, 48, 43, 49, 93, |
- | |
967 | 32, 46, 46, 32,104,101,120, 95,115,116,114, 10,101,110,100, |
- | |
968 | 10,110, 32, 61, 32,109, 97,116,104, 46,102,108,111,111,114, |
- | |
969 | 40,110, 47, 49, 54, 41, 10,101,110,100, 10,105,102, 40,104, |
- | |
970 | 101,120, 95,115,116,114, 32, 61, 61, 32, 34, 34, 41, 32,116, |
- | |
971 | 104,101,110, 10,104,101,120, 95,115,116,114, 32, 61, 32, 34, |
- | |
972 | 48, 34, 10,101,110,100, 10,114,101,116,117,114,110, 32, 34, |
- | |
973 | 48,120, 34, 32, 46, 46, 32,104,101,120, 95,115,116,114, 10, |
- | |
974 | 101,110,100, 10,108,111, 99, 97,108, 32,102,117,110, 99,116, |
- | |
975 | 105,111,110, 32,116,111, 95,100,101, 99, 40,104,101,120, 41, |
- | |
976 | 10,105,102, 40,116,121,112,101, 40,104,101,120, 41, 32,126, |
- | |
977 | 61, 32, 34,115,116,114,105,110,103, 34, 41, 32,116,104,101, |
- | |
978 | 110, 10,101,114,114,111,114, 40, 34,110,111,110, 45,115,116, |
- | |
979 | 114,105,110,103, 32,116,121,112,101, 32,112, 97,115,115,101, |
- | |
980 | 100, 32,105,110, 46, 34, 41, 10,101,110,100, 10,104,101, 97, |
- | |
981 | 100, 32, 61, 32,115,116,114,105,110,103, 46,115,117, 98, 40, |
- | |
982 | 104,101,120, 44, 32, 49, 44, 32, 50, 41, 10,105,102, 40, 32, |
- | |
983 | 104,101, 97,100, 32,126, 61, 32, 34, 48,120, 34, 32, 97,110, |
- | |
984 | 100, 32,104,101, 97,100, 32,126, 61, 32, 34, 48, 88, 34, 41, |
- | |
985 | 32,116,104,101,110, 10,101,114,114,111,114, 40, 34,119,114, |
- | |
986 | 111,110,103, 32,104,101,120, 32,102,111,114,109, 97,116, 44, |
- | |
987 | 32,115,104,111,117,108,100, 32,108,101, 97,100, 32, 98,121, |
- | |
988 | 32, 48,120, 32,111,114, 32, 48, 88, 46, 34, 41, 10,101,110, |
- | |
989 | 100, 10,118, 32, 61, 32,116,111,110,117,109, 98,101,114, 40, |
- | |
990 | 115,116,114,105,110,103, 46,115,117, 98, 40,104,101,120, 44, |
- | |
991 | 32, 51, 41, 44, 32, 49, 54, 41, 10,114,101,116,117,114,110, |
- | |
992 | 32,118, 59, 10,101,110,100, 10,104,101,120, 32, 61, 32,123, |
- | |
993 | 10,116,111, 95,100,101, 99, 32, 61, 32,116,111, 95,100,101, |
- | |
994 | 99, 44, 10,116,111, 95,104,101,120, 32, 61, 32,116,111, 95, |
- | |
995 | 104,101,120, 44, 10,125, 10,101,110,100, 10,100, 32, 61, 32, |
- | |
996 | 52, 51, 52, 49, 54, 56, 56, 10,104, 32, 61, 32,116,111, 95, |
- | |
997 | 104,101,120, 40,100, 41, 10,112,114,105,110,116, 40,104, 41, |
- | |
998 | 10,112,114,105,110,116, 40,116,111, 95,100,101, 99, 40,104, |
- | |
999 | 41, 41, 10,102,111,114, 32,105, 32, 61, 32, 49, 44, 32, 49, |
- | |
1000 | 48, 48, 48, 48, 48, 32,100,111, 10,104, 32, 61, 32,104,101, |
- | |
1001 | 120, 46,116,111, 95,104,101,120, 40,105, 41, 10,100, 32, 61, |
- | |
1002 | 32,104,101,120, 46,116,111, 95,100,101, 99, 40,104, 41, 10, |
- | |
1003 | 105,102, 40,100, 32,126, 61, 32,105, 41, 32,116,104,101,110, |
- | |
1004 | 10,101,114,114,111,114, 40, 34,102, 97,105,108,101,100, 32, |
- | |
1005 | 34, 32, 46, 46, 32,105, 32, 46, 46, 32, 34, 44, 32, 34, 32, |
- | |
1006 | 46, 46, 32,104, 41, 10,101,110,100, 10,101,110,100, 10,32 |
- | |
1007 | }; |
- | |
1008 | tolua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua: embedded Lua code 2"); |
- | |
1009 | lua_settop(tolua_S, top); |
- | |
1010 | } /* end of embedded lua code */ |
- | |
1011 | - | ||
1012 | tolua_endmodule(tolua_S); |
- | |
1013 | return 1; |
- | |
1014 | } |
- | |
1015 | - | ||
1016 | - | ||
1017 | #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501 |
- | |
1018 | TOLUA_API int luaopen_sjasm (lua_State* tolua_S) { |
- | |
1019 | return tolua_sjasm_open(tolua_S); |
- | |
1020 | } |
- | |
1021 | #endif |
- | |
1022 | - | ||
1023 | - | ||
1024 | - | ||
1025 | - | ||
1026 | - | ||
1027 | - | ||
1028 | - | ||
1029 | - | ||
1030 | - | ||
1031 | - | ||
1032 | - | ||
1033 | - | ||
1034 | - | ||
1035 | - | ||
1036 | - | ||
1037 | - | ||
1038 | - | ||
1039 | - | ||
1040 | - | ||
1041 | - | ||
1042 | - | ||
1043 | - | ||
1044 | - | ||
1045 | - | ||
1046 | - | ||
1047 | - | ||
1048 | - | ||
1049 | - | ||
1050 | - | ||
1051 | - | ||
1052 | - | ||
1053 | - | ||
1054 | - | ||
1055 | - | ||
1056 | - | ||
1057 | - | ||
1058 | - | ||
1059 | - | ||
1060 | - | ||
1061 | - | ||
1062 | - | ||
1063 | - | ||
1064 | - | ||
1065 | - | ||
1066 | - | ||
1067 | - | ||
1068 | - | ||
1069 | - | ||
1070 | - | ||
1071 | - | ||
1072 | - | ||
1073 | - | ||
1074 | - | ||
1075 | - | ||
1076 | - | ||
1077 | - | ||
1078 | - | ||
1079 | - | ||
1080 | - | ||
1081 | - | ||
1082 | - | ||
1083 | - | ||
1084 | - | ||
1085 | - | ||
1086 | - | ||
1087 | - | ||
1088 | - | ||
1089 | - | ||
1090 | - | ||
1091 | - | ||
1092 | - | ||
1093 | - | ||
1094 | - | ||
1095 | - | ||
1096 | - | ||
1097 | - | ||
1098 | - | ||
1099 | - | ||
1100 | - | ||
1101 | - | ||
1102 | - | ||
1103 | - | ||
1104 | - | ||
1105 | - | ||
1106 | - | ||
1107 | - | ||
1108 | - | ||
1109 | - | ||
1110 | - | ||
1111 | - | ||
1112 | - | ||
1113 | - | ||
1114 | - | ||
1115 | - | ||
1116 | - | ||
1117 | - | ||
1118 | - | ||
1119 | - | ||
1120 | - | ||
1121 | - | ||
1122 | - | ||
1123 | - | ||
1124 | - | ||
1125 | - | ||
1126 | - | ||
1127 | - | ||
1128 | - | ||
1129 | - | ||
1130 | - | ||
1131 | - | ||
1132 | - | ||
1133 | - | ||
1134 | - | ||
1135 | - | ||
1136 | - | ||
1137 | - | ||
1138 | - | ||
1139 | - | ||
1140 | - | ||
1141 | - | ||
1142 | - | ||
1143 | - | ||
1144 | - | ||
1145 | - | ||
1146 | - | ||
1147 | - | ||
1148 | - | ||
1149 | - | ||
1150 | - | ||
1151 | - | ||
1152 | - | ||
1153 | - | ||
1154 | - | ||
1155 | - | ||
1156 | - | ||
1157 | - | ||
1158 | - | ||
1159 | - | ||
1160 | - | ||
1161 | - | ||
1162 | - | ||
1163 | - | ||
1164 | - | ||
1165 | - | ||
1166 | - | ||
1167 | - | ||
1168 | - | ||
1169 | - | ||
1170 | - | ||
1171 | - | ||
1172 | - | ||
1173 | - | ||
1174 | - | ||
1175 | - | ||
1176 | - | ||
1177 | - | ||
1178 | - | ||
1179 | - | ||
1180 | - | ||
1181 | - | ||
1182 | - | ||
1183 | - | ||
1184 | - | ||
1185 | - | ||
1186 | - | ||
1187 | - | ||
1188 | - | ||
1189 | - | ||
1190 | - | ||
1191 | - | ||
1192 | - | ||
1193 | - | ||
1194 | - | ||
1195 | - | ||
1196 | - | ||
1197 | - | ||
1198 | - | ||
1199 | - | ||
1200 | - | ||
1201 | - | ||
1202 | - | ||
1203 | - | ||
1204 | - | ||
1205 | - | ||
1206 | - | ||
1207 | - | ||
1208 | - | ||
1209 | - | ||
1210 | - | ||
1211 | - | ||
1212 | - | ||
1213 | - | ||
1214 | - | ||
1215 | - | ||
1216 | - | ||
1217 | - | ||
1218 | - | ||
1219 | - | ||
1220 | - | ||
1221 | - | ||
1222 | - | ||
1223 | - | ||
1224 | - | ||
1225 | - | ||
1226 | - | ||
1227 | - | ||
1228 | - | ||
1229 | - | ||
1230 | - | ||
1231 | 552 | ||
- | 553 | //eof lua_sjasm.cpp |