mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
support " and void line in main.py
This commit is contained in:
parent
76ca309f56
commit
3ffb28afd6
@ -4,5 +4,7 @@ import PikaStdData
|
||||
import PikaMath
|
||||
from PikaObj import *
|
||||
|
||||
print("hello pikascript!\n")
|
||||
for i in range(0, 100):
|
||||
|
||||
print(i)
|
||||
|
@ -45,7 +45,7 @@
|
||||
#endif
|
||||
/* default PIKA_WEAK */
|
||||
#ifndef PIKA_WEAK
|
||||
#define PIKA_WEAK
|
||||
#define PIKA_WEAK __attribute__((weak))
|
||||
#endif
|
||||
|
||||
/* OS */
|
||||
|
@ -9,9 +9,10 @@ line.moveTo(20)
|
||||
while True:
|
||||
if right.read() == 1:
|
||||
print('right')
|
||||
|
||||
if left.read() == 0:
|
||||
print('left')
|
||||
print("left")
|
||||
if up.read() == 0:
|
||||
print('up')
|
||||
print('up\n')
|
||||
if down.read() == 0:
|
||||
print('down')
|
||||
|
@ -113,10 +113,25 @@ impl ClassInfo {
|
||||
|
||||
pub fn script_fn(&self) -> String {
|
||||
let mut script_fn = String::new();
|
||||
script_fn.push_str("PikaObj * pikaScriptInit(){\r\n");
|
||||
/* add pikaScriptInit function define */
|
||||
script_fn.push_str("PikaObj * pikaScriptInit(void){\r\n");
|
||||
/* create the root object */
|
||||
script_fn.push_str(" PikaObj * pikaMain = newRootObj(\"pikaMain\", New_PikaMain);\r\n");
|
||||
/* use obj_run to run the script in main.py */
|
||||
script_fn.push_str(" obj_run(pikaMain,\n");
|
||||
script_fn.push_str(&self.script_list.content);
|
||||
/* get the origin script content */
|
||||
let script_content_origin = String::from(&self.script_list.content);
|
||||
/* filters for the script content */
|
||||
/* remove void line */
|
||||
let script_content = String::from(&script_content_origin).replace("@BEGIN@@END@", "");
|
||||
/* use \" instead of " */
|
||||
let script_content = script_content.replace("\"", "\\\"");
|
||||
/* add begin and end */
|
||||
let script_content = script_content.replace("@BEGIN@", " \"");
|
||||
let script_content = script_content.replace("@END@", "\\n\"\n");
|
||||
/* add the script content */
|
||||
script_fn.push_str(&script_content);
|
||||
/* add the END of script string */
|
||||
script_fn.push_str(" \"\\n\");\n");
|
||||
script_fn.push_str(" return pikaMain;\r\n");
|
||||
script_fn.push_str("}\r\n\r\n");
|
||||
|
@ -13,9 +13,11 @@ use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
|
||||
fn main() {
|
||||
/* new a compiler, sellect to path */
|
||||
let mut compiler = Compiler::new(String::from(""), String::from("pikascript-api/"));
|
||||
/* analyze file begin with main.py */
|
||||
compiler = Compiler::analyze_file(compiler, String::from("main"), false);
|
||||
/* write to compiler-info about the info */
|
||||
/* write the infomatrion to compiler-info */
|
||||
let mut compiler_info_file =
|
||||
File::create(format!("{}compiler-info.txt", compiler.dist_path)).unwrap();
|
||||
let compiler_info = format!("{:?}", compiler);
|
||||
@ -82,21 +84,26 @@ fn main() {
|
||||
/* make the pikascript.c */
|
||||
let api_file_path = format!("{}pikaScript.c", compiler.dist_path);
|
||||
let mut f = File::create(api_file_path).unwrap();
|
||||
/* add head */
|
||||
f.write("/* ******************************** */\n".as_bytes())
|
||||
.unwrap();
|
||||
f.write("/* Warning! Don't modify this file! */\n".as_bytes())
|
||||
.unwrap();
|
||||
f.write("/* ******************************** */\n".as_bytes())
|
||||
.unwrap();
|
||||
/* add include */
|
||||
f.write("#include \"PikaMain.h\"\n".as_bytes()).unwrap();
|
||||
f.write("#include <stdio.h>\n".as_bytes()).unwrap();
|
||||
f.write("#include <stdlib.h>\n".as_bytes()).unwrap();
|
||||
f.write("\n".as_bytes()).unwrap();
|
||||
/* get script from main.py */
|
||||
let pika_main = compiler
|
||||
.class_list
|
||||
.get_mut(&"PikaMain".to_string())
|
||||
.unwrap();
|
||||
/* add script function */
|
||||
f.write(pika_main.script_fn().as_bytes()).unwrap();
|
||||
|
||||
/* make the pikascript.h */
|
||||
let api_file_path = format!("{}pikaScript.h", compiler.dist_path);
|
||||
let mut f = File::create(api_file_path).unwrap();
|
||||
@ -115,7 +122,7 @@ fn main() {
|
||||
f.write("#include \"PikaObj.h\"\n".as_bytes()).unwrap();
|
||||
f.write("#include \"PikaMain.h\"\n".as_bytes()).unwrap();
|
||||
f.write("\n".as_bytes()).unwrap();
|
||||
f.write("PikaObj * pikaScriptInit();\n".as_bytes()).unwrap();
|
||||
f.write("PikaObj * pikaScriptInit(void);\n".as_bytes()).unwrap();
|
||||
f.write("\n".as_bytes()).unwrap();
|
||||
f.write("#endif\n".as_bytes()).unwrap();
|
||||
}
|
||||
|
@ -30,6 +30,6 @@ impl Script {
|
||||
return false;
|
||||
}
|
||||
pub fn obj_run(cmd: &String) -> String {
|
||||
return format!(" \"{}\\n\"\n", cmd);
|
||||
return format!("@BEGIN@{}@END@", cmd);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user