about to add ret and break
This commit is contained in:
parent
b386ebc849
commit
45af9b9d39
|
@ -7,3 +7,4 @@ tlang/build
|
|||
tlang/tlang
|
||||
tlang/my_junk_scripts
|
||||
wrappergen/dest
|
||||
wrappergen/wrappers
|
|
@ -9,7 +9,7 @@
|
|||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/tlang/tlang",
|
||||
"args": ["${workspaceFolder}/debugging/tlang_wrapper_gen.tlang","${workspaceFolder}/debugging/src.txt","${workspaceFolder}/debugging/dest"],
|
||||
"args": ["${workspaceFolder}/tlang/my_junk_scripts/https_tesses.tlang"],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${fileDirname}",
|
||||
"environment": [],
|
||||
|
|
|
@ -15,7 +15,7 @@ include $(DEVKITPPC)/wii_rules
|
|||
# SOURCES is a list of directories containing source code
|
||||
# INCLUDES is a list of directories containing extra header files
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := $(notdir $(CURDIR))
|
||||
TARGET := boot
|
||||
BUILD := build_wii
|
||||
SOURCES := src
|
||||
DATA := data
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#define USE_SDL2
|
||||
#define USE_NETWORK
|
||||
#define USE_WIISOCKETS_ON_WII //comment out for #include <network.h>
|
||||
#define USE_THREADS
|
||||
#define USE_MBED
|
||||
//#define USE_SDL2
|
||||
//#define USE_NETWORK
|
||||
//#define USE_WIISOCKETS_ON_WII //comment out for #include <network.h>
|
||||
//#define USE_THREADS
|
||||
//#define USE_MBED
|
||||
//#define USE_GTK
|
|
@ -105,6 +105,7 @@ struct tobject
|
|||
};
|
||||
struct runtime
|
||||
{
|
||||
bool hasStd;
|
||||
runtime_reg_t reg;
|
||||
node_t* program;
|
||||
scope_t* globals;
|
||||
|
@ -445,3 +446,13 @@ string_t* path_getextension(string_t* a);
|
|||
string_t* path_filename(string_t* a);
|
||||
string_t* path_parent(string_t* a);
|
||||
void runtime_add_argument(runtime_t* rt,tobject_t* arg);
|
||||
char* fs_tlang_config_dir();
|
||||
void runtime_register_std(runtime_t* rt);
|
||||
|
||||
void runtime_create_number_on_dict(dict_t* dict,char* name,runtime_t* rt,double number);
|
||||
void runtime_create_bool_on_dict(dict_t* dict,char* name,runtime_t* rt,bool value);
|
||||
void runtime_create_string_on_dict(dict_t* dict,char* name,runtime_t* rt,const char* value);
|
||||
void runtime_create_method_on_object(tobject_t* tdict_obj,char* name,runtime_t* rt,void* ptr,external_method_t cb,texternalmethod_free_t free);
|
||||
void runtime_create_number_on_object(tobject_t* tdict_obj,char* name,runtime_t* rt,double number);
|
||||
void runtime_create_bool_on_object(tobject_t* tdict_obj,char* name,runtime_t* rt,bool value);
|
||||
void runtime_create_string_on_object(tobject_t* tdict_obj,char* name,runtime_t* rt,const char* text);
|
|
@ -0,0 +1,18 @@
|
|||
#include "tlang.h"
|
||||
|
||||
char _little = -1;
|
||||
|
||||
bool endian_islittle()
|
||||
{
|
||||
if(_little == -1)
|
||||
{
|
||||
char _data[2];
|
||||
_data[0] = 42;
|
||||
_data[1] = 0;
|
||||
short num = *(short*)_data;
|
||||
int little = num == 42 ? 1 : 0;;
|
||||
_little = little;
|
||||
return little;
|
||||
}
|
||||
return _little == 1;
|
||||
}
|
|
@ -16,6 +16,41 @@ char fs_env_sep()
|
|||
return ':';
|
||||
#endif
|
||||
}
|
||||
char* config_dir = NULL;
|
||||
|
||||
char* fs_tlang_config_dir()
|
||||
{
|
||||
Global_Mutex_Lock();
|
||||
if(config_dir == NULL)
|
||||
{
|
||||
#if defined(GEKKO)
|
||||
config_dir="/TLang";
|
||||
#elif defined(WIN32) || defined(_WIN32)
|
||||
|
||||
#elif defined(__linux__)
|
||||
char* cfg = getenv("XDG_CONFIG_DIR");
|
||||
if(cfg == NULL)
|
||||
{
|
||||
char* cfg2 = getenv("HOME");
|
||||
if(cfg2 == NULL)
|
||||
{
|
||||
config_dir = "TLangConfig";
|
||||
}else{
|
||||
size_t len=strlen(cfg2) + strlen("/.config") + 1;
|
||||
cfg = (char*)malloc(len * sizeof(char));
|
||||
snprintf(cfg,len,"%s/.config",cfg2);
|
||||
config_dir = cfg;
|
||||
}
|
||||
}
|
||||
#else
|
||||
config_dir = "TLangConfig";
|
||||
#endif
|
||||
}
|
||||
char* _cfg = config_dir;
|
||||
Global_Mutex_Unlock();
|
||||
|
||||
return _cfg;
|
||||
}
|
||||
|
||||
string_t* path_parent(string_t* a)
|
||||
{
|
||||
|
|
|
@ -58,9 +58,9 @@ tobject_t* __node_getarray_execute(node_t* n,scope_t* s)
|
|||
}
|
||||
if(parent_obj->type == tdict)
|
||||
{
|
||||
if(dict_haskey(parent_obj->data.string,"at"))
|
||||
if(dict_haskey(parent_obj->data.dict,"at"))
|
||||
{
|
||||
tobject_t* obj=dict_getkvp(parent_obj->data.string,"at")->value;
|
||||
tobject_t* obj=dict_getkvp(parent_obj->data.dict,"at")->value;
|
||||
if(obj->type == tinternalmethod || obj->type == texternalmethod)
|
||||
{
|
||||
list_tobject_t args;
|
||||
|
@ -150,9 +150,9 @@ void __node_setarray_execute(node_t* n,tobject_t* variable_obj,scope_t* s)
|
|||
}*/
|
||||
if(parent_obj->type == tdict)
|
||||
{
|
||||
if(dict_haskey(parent_obj->data.string,"setAt"))
|
||||
if(dict_haskey(parent_obj->data.dict,"setAt"))
|
||||
{
|
||||
tobject_t* obj=dict_getkvp(parent_obj->data.string,"setAt")->value;
|
||||
tobject_t* obj=dict_getkvp(parent_obj->data.dict,"setAt")->value;
|
||||
if(obj->type == tinternalmethod || obj->type == texternalmethod)
|
||||
{
|
||||
list_tobject_t args;
|
||||
|
|
|
@ -57,15 +57,18 @@ int main(int argc, char **argv) {
|
|||
if(f)
|
||||
{
|
||||
runtime_t* rt=runtime_init();
|
||||
runtime_register_std(rt);
|
||||
runtime_register(rt,__reg_wii);
|
||||
|
||||
string_t* s = string_create();
|
||||
string_read(s,f,fread);
|
||||
runtime_load(rt,s);
|
||||
string_free(s);
|
||||
|
||||
fclose(f);
|
||||
printf("Loaded Script\n");
|
||||
tobject_t* o = runtime_exec(rt);
|
||||
|
||||
tobject_t* o= rt->program->execute(rt->program,rt->globals);
|
||||
tobject_freeifzero(o);
|
||||
runtime_free(rt);
|
||||
}else{
|
||||
|
|
|
@ -0,0 +1,160 @@
|
|||
|
||||
#include "tlang.h"
|
||||
#if defined(USE_MBED)
|
||||
#include <mbedtls/ssl.h>
|
||||
#include <mbedtls/platform.h>
|
||||
#include <mbedtls/entropy.h>
|
||||
#include <mbedtls/debug.h>
|
||||
#include <mbedtls/ctr_drbg.h>
|
||||
static void my_debug(void *ctx, int level,
|
||||
const char *file, int line,
|
||||
const char *str)
|
||||
{
|
||||
((void) level);
|
||||
|
||||
mbedtls_fprintf((FILE *) ctx, "%s:%04d: %s", file, line, str);
|
||||
fflush((FILE *) ctx);
|
||||
}
|
||||
int mbedsend_tstream(void* ptr,const unsigned char* data,size_t len)
|
||||
{
|
||||
stream_t* strm = (stream_t*)ptr;
|
||||
stream_write(strm,data,len);
|
||||
return (int)len;
|
||||
}
|
||||
int mbedrecv_tstream(void* ptr,unsigned char* data,size_t len)
|
||||
{
|
||||
stream_t* strm = (stream_t*)ptr;
|
||||
return (int)stream_read(strm,data,len);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
stream_t* baseStrm;
|
||||
bool ignoreSSL;
|
||||
mbedtls_entropy_context entropy;
|
||||
mbedtls_ctr_drbg_context ctr_drbg;
|
||||
mbedtls_ssl_context ssl;
|
||||
mbedtls_ssl_config conf;
|
||||
mbedtls_x509_crt cacert;
|
||||
|
||||
} mbedtls_tlang_handle_t;
|
||||
int64_t _ssl_read(stream_t* strm,void* data,int64_t sz)
|
||||
{
|
||||
mbedtls_tlang_handle_t* handle = (mbedtls_tlang_handle_t*)strm->ptr;
|
||||
return mbedtls_ssl_read(&handle->ssl,(unsigned char*)data,(size_t)sz);
|
||||
}
|
||||
void _ssl_write(stream_t* strm,void* data,int64_t sz)
|
||||
{
|
||||
mbedtls_tlang_handle_t* handle = (mbedtls_tlang_handle_t*)strm->ptr;
|
||||
mbedtls_ssl_write(&handle->ssl,(const unsigned char*)data,(size_t)sz);
|
||||
|
||||
}
|
||||
runtime_t* security_sslstream_asclient(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length > 0 && args->items[0]->type == tstring)
|
||||
{
|
||||
mbedtls_tlang_handle_t* handle = (mbedtls_tlang_handle_t*)ptr;
|
||||
|
||||
mbedtls_ssl_init(&handle->ssl);
|
||||
mbedtls_ssl_config_init(&handle->conf);
|
||||
mbedtls_x509_crt_init(&handle->cacert);
|
||||
mbedtls_ctr_drbg_init(&handle->ctr_drbg);
|
||||
mbedtls_entropy_init(&handle->entropy);
|
||||
mbedtls_ctr_drbg_seed(&handle->ctr_drbg, mbedtls_entropy_func, &handle->entropy,
|
||||
"TLANG SSL",
|
||||
strlen("TLANG SSL"));
|
||||
string_t* fs = string_create();
|
||||
string_appendp(fs,fs_tlang_config_dir());
|
||||
bool has=false;
|
||||
if(fs_dir_exists(fs))
|
||||
{
|
||||
string_t* certs = string_create();
|
||||
string_appendp(certs,"tls_certs.pem");
|
||||
|
||||
string_t* f=path_join(fs,certs);
|
||||
string_free(fs);
|
||||
fs=f;
|
||||
string_free(certs);
|
||||
if(fs_file_exists(fs))
|
||||
{
|
||||
has=true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(has)
|
||||
{
|
||||
string_t* text = string_create();
|
||||
char* name = string_dupp(fs);
|
||||
FILE* f = fopen(fs,"r");
|
||||
free(name);
|
||||
string_read(text,f,fread);
|
||||
fclose(f);
|
||||
mbedtls_x509_crt_parse(&handle->cacert,text->text,text->length);
|
||||
mbedtls_ssl_conf_authmode(&handle->conf,handle->ignoreSSL ? MBEDTLS_SSL_VERIFY_OPTIONAL : MBEDTLS_SSL_VERIFY_REQUIRED);
|
||||
mbedtls_ssl_conf_ca_chain(&handle->conf, &handle->cacert, NULL);
|
||||
} else {
|
||||
mbedtls_ssl_conf_authmode(&handle->conf, MBEDTLS_SSL_VERIFY_NONE);
|
||||
|
||||
}
|
||||
string_free(fs);
|
||||
mbedtls_ssl_conf_rng(&handle->conf, mbedtls_ctr_drbg_random, &handle->ctr_drbg);
|
||||
mbedtls_ssl_conf_dbg(&handle->conf, my_debug, stdout);
|
||||
mbedtls_ssl_setup(&handle->ssl, &handle->conf);
|
||||
char* host = string_dupp(args->items[0]->data.string);
|
||||
mbedtls_ssl_set_hostname(&handle->ssl,host);
|
||||
free(host);
|
||||
mbedtls_ssl_set_bio(&handle->ssl,handle->baseStrm,mbedsend_tstream,mbedrecv_tstream,NULL);
|
||||
int res = mbedtls_ssl_handshake(&handle->ssl);
|
||||
|
||||
|
||||
|
||||
if(mbedtls_ssl_get_verify_result(&handle->ssl) != 0)
|
||||
{
|
||||
mbedtls_ssl_free(&handle->ssl);
|
||||
return tobject_bool(rt,false);
|
||||
}
|
||||
return tobject_bool(rt,true);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
void security_sslstream_setextra(stream_t * strm, tobject_t* obj, runtime_t* rt, void* ptr)
|
||||
{
|
||||
runtime_create_method_on_dict(obj->data.dict,"as_client",rt,ptr,security_sslstream_asclient,NULL);
|
||||
}
|
||||
void _ssl_free(stream_t* strm)
|
||||
{
|
||||
mbedtls_tlang_handle_t* handle = (mbedtls_tlang_handle_t*)strm->ptr;
|
||||
mbedtls_ssl_free(&handle->ssl);
|
||||
}
|
||||
void _ssl_flush(stream_t* strm)
|
||||
{
|
||||
|
||||
}
|
||||
tobject_t* security_sslstream_external_method(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 3 && args->items[0]->type == tdict && args->items[1]->type == tbool && args->items[2]->type == tbool ) {
|
||||
stream_t* strm = tobject_tostream(rt->globals,args->items[0],!args->items[1]->data.boolean);
|
||||
|
||||
mbedtls_tlang_handle_t* handle = (mbedtls_tlang_handle_t*)malloc(sizeof(mbedtls_tlang_handle_t));
|
||||
memset(handle,0,sizeof(mbedtls_tlang_handle_t));
|
||||
handle->ignoreSSL = args->items[2]->data.boolean;
|
||||
handle->baseStrm = strm;
|
||||
|
||||
stream_t* newStrm= stream_create(handle,_ssl_read,_ssl_write,NULL,NULL,NULL,stream_true,stream_true,NULL,_ssl_free,_ssl_flush);
|
||||
newStrm->set_extra_methods = security_sslstream_setextra;
|
||||
newStrm->set_extra_methods_data = handle;
|
||||
return tobject_fromstream(rt,newStrm);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
|
||||
void runtime_register_mbed(runtime_t* rt)
|
||||
{
|
||||
tobject_t* mbed = tobject_create(rt);
|
||||
mbed->type = tdict;
|
||||
mbed->data.dict = dict_create();
|
||||
|
||||
runtime_create_method_on_dict(mbed->data.dict,"sslstream",rt,NULL,security_sslstream_external_method,NULL);
|
||||
rt->globals->setvariable(rt->globals,"security",mbed);
|
||||
}
|
||||
#endif
|
|
@ -1,6 +1,7 @@
|
|||
#include "tlang.h"
|
||||
#include <ctype.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
tobject_t* __node_method_call_execute(node_t* n,scope_t* s)
|
||||
{
|
||||
node_t* parent=n->data.variable_node.parent;
|
||||
|
@ -261,7 +262,7 @@ tobject_t* __node_method_call_execute(node_t* n,scope_t* s)
|
|||
tobject_t* val = NULL;
|
||||
if(argcount >= 2)
|
||||
{
|
||||
val = args[1]->execute(args[1],val);
|
||||
val = args[1]->execute(args[1],s);
|
||||
o=val;
|
||||
}
|
||||
else if(argcount == 1)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "tlang.h"
|
||||
|
||||
#if defined(USE_NETWORK)
|
||||
#include <errno.h>
|
||||
#if defined(GEKKO)
|
||||
#if defined(HW_RVL) && defined(USE_WIISOCKETS_ON_WII)
|
||||
#define USE_NORMAL_SOCKETS
|
||||
|
@ -102,8 +103,10 @@
|
|||
free(ipAddress);
|
||||
addr.sin_port = htons((uint16_t)port);
|
||||
addr.sin_family = AF_INET;
|
||||
if(connect(fd,&addr,sizeof(struct sockaddr_in)) != 0)
|
||||
int res = connect(fd,&addr,sizeof(struct sockaddr_in));
|
||||
if(res != 0)
|
||||
{
|
||||
printf("ERROR AT NET: %s\n",strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
return create_netfd_strm(fd);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
#if defined(USE_SDL2)
|
||||
extern void runtime_register_sdl2(runtime_t* rt);
|
||||
extern void runtime_register_sdl(runtime_t* rt);
|
||||
#endif
|
||||
#if defined(USE_THREADS)
|
||||
extern void register_register_threads(runtime_t* rt,dict_t* create);
|
||||
|
@ -16,6 +16,9 @@ extern void register_register_threads(runtime_t* rt,dict_t* create);
|
|||
#if defined(USE_NETWORK)
|
||||
extern void runtime_register_network(runtime_t* rt);
|
||||
#endif
|
||||
#if defined(USE_MBED)
|
||||
extern void runtime_register_mbed(runtime_t* rt);
|
||||
#endif
|
||||
extern tobject_t* __ls_free(runtime_t* rt,void* ptr,list_tobject_t* ls);
|
||||
extern tobject_t* __ls_get_current(runtime_t* rt,void* ptr,list_tobject_t* ls);
|
||||
extern tobject_t* __ls_movenext(runtime_t* rt,void* ptr,list_tobject_t* ls);
|
||||
|
@ -28,6 +31,43 @@ void runtime_create_method_on_dict(dict_t* dict,char* name,runtime_t* rt,void* p
|
|||
|
||||
dict_setkvp(dict,k);
|
||||
}
|
||||
void runtime_create_number_on_dict(dict_t* dict,char* name,runtime_t* rt,double number)
|
||||
{
|
||||
kvp_t k;
|
||||
k.key = name;
|
||||
k.value = tobject_number(rt,number);
|
||||
dict_setkvp(dict,k);
|
||||
}
|
||||
void runtime_create_bool_on_dict(dict_t* dict,char* name,runtime_t* rt,bool value)
|
||||
{
|
||||
kvp_t k;
|
||||
k.key = name;
|
||||
k.value = tobject_bool(rt,value);
|
||||
dict_setkvp(dict,k);
|
||||
}
|
||||
void runtime_create_string_on_dict(dict_t* dict,char* name,runtime_t* rt,const char* value)
|
||||
{
|
||||
kvp_t k;
|
||||
k.key = name;
|
||||
k.value = tobject_stringp(rt,value);
|
||||
dict_setkvp(dict,k);
|
||||
}
|
||||
void runtime_create_method_on_object(tobject_t* tdict_obj,char* name,runtime_t* rt,void* ptr,external_method_t cb,texternalmethod_free_t free)
|
||||
{
|
||||
runtime_create_method_on_dict(tdict_obj->data.dict,name,rt,ptr,cb,free);
|
||||
}
|
||||
void runtime_create_number_on_object(tobject_t* tdict_obj,char* name,runtime_t* rt,double number)
|
||||
{
|
||||
runtime_create_number_on_dict(tdict_obj->data.dict,name,rt,number);
|
||||
}
|
||||
void runtime_create_bool_on_object(tobject_t* tdict_obj,char* name,runtime_t* rt,bool value)
|
||||
{
|
||||
runtime_create_bool_on_dict(tdict_obj->data.dict,name,rt,value);
|
||||
}
|
||||
void runtime_create_string_on_object(tobject_t* tdict_obj,char* name,runtime_t* rt,const char* text)
|
||||
{
|
||||
runtime_create_string_on_dict(tdict_obj->data.dict,name,rt,text);
|
||||
}
|
||||
tobject_t* __console_clear_external_method(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
#if defined(_WIN32) || defined(WIN32)
|
||||
|
@ -219,6 +259,8 @@ typedef struct {
|
|||
tobject_t* exe;
|
||||
tobject_t* root;
|
||||
tobject_t* addArg;
|
||||
tobject_t* std;
|
||||
bool stdValue;
|
||||
} exec_free_ctx_t;
|
||||
void __code_rt_free(tobject_t* o)
|
||||
{
|
||||
|
@ -226,14 +268,16 @@ void __code_rt_free(tobject_t* o)
|
|||
free(ctx->root);
|
||||
free(ctx->exe);
|
||||
free(ctx->addArg);
|
||||
free(ctx->std);
|
||||
runtime_free(ctx->rt);
|
||||
free(ctx);
|
||||
}
|
||||
tobject_t* __execute_code_rt(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
runtime_t* rt2 = (runtime_t*)ptr;
|
||||
exec_free_ctx_t* rt2 = (exec_free_ctx_t*)ptr;
|
||||
if(rt2->stdValue) {runtime_register_std(rt2->rt);}
|
||||
|
||||
return runtime_exec(rt);
|
||||
return runtime_exec(rt2->rt);
|
||||
}
|
||||
tobject_t* runtime_exec(runtime_t* rt)
|
||||
{
|
||||
|
@ -259,6 +303,15 @@ tobject_t* __add_argument(runtime_t* rt,void* ptr,list_tobject_t* args)
|
|||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* __setstd_rt(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
exec_free_ctx_t* ctx = (exec_free_ctx_t*)ptr;
|
||||
if(args->length > 0 && args->items[0]->type == tbool)
|
||||
{
|
||||
ctx->stdValue = args->items[0]->data.boolean;
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* __reflection_parse_code(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length > 0 && args->items[0]->type == tstring)
|
||||
|
@ -281,20 +334,28 @@ tobject_t* __reflection_parse_code(runtime_t* rt,void* ptr,list_tobject_t* args)
|
|||
kvp.key = "add";
|
||||
add_arg->count = 65535;
|
||||
kvp.value = add_arg;
|
||||
dict_setkvp(d->data.dict,kvp);
|
||||
exec_free_ctx_t* __free_Data = (exec_free_ctx_t*)malloc(sizeof(exec_free_ctx_t));
|
||||
__free_Data->stdValue=true;
|
||||
tobject_t* std = tobject_fromexternalmethod(rt,__free_Data,__setstd_rt,NULL);
|
||||
kvp.key = "setstd";
|
||||
std->count = 65535;
|
||||
kvp.value = std;
|
||||
|
||||
dict_setkvp(d->data.dict,kvp);
|
||||
d->free = __code_rt_free;
|
||||
tobject_t* exe = tobject_fromexternalmethod(rt,rt2,__execute_code_rt,NULL);
|
||||
tobject_t* exe = tobject_fromexternalmethod(rt,__free_Data,__execute_code_rt,NULL);
|
||||
kvp.key = "run";
|
||||
exe->count = 65535;
|
||||
kvp.value = exe;
|
||||
dict_setkvp(d->data.dict,kvp);
|
||||
d->free = __code_rt_free;
|
||||
exec_free_ctx_t* __free_Data = (exec_free_ctx_t*)malloc(sizeof(exec_free_ctx_t));
|
||||
|
||||
__free_Data->exe = exe;
|
||||
__free_Data->root = d2;
|
||||
__free_Data->rt = rt2;
|
||||
__free_Data->addArg = add_arg;
|
||||
__free_Data->std = std;
|
||||
d->ptr_data = __free_Data;
|
||||
return d;
|
||||
}
|
||||
|
@ -778,20 +839,13 @@ void runtime_register(runtime_t* rt,runtime_reg_t reg)
|
|||
reg(rt);
|
||||
}
|
||||
|
||||
runtime_t* runtime_init()
|
||||
void runtime_register_std(runtime_t* rt)
|
||||
{
|
||||
runtime_t* rt = (runtime_t*)malloc(sizeof(runtime_t));
|
||||
rt->globals = NULL;
|
||||
rt->program=NULL;
|
||||
rt->reg=NULL;
|
||||
list_create(rt,&rt->args,0);
|
||||
scope_create_root(rt);
|
||||
tobject_t* __fs = tobject_create(rt);
|
||||
if(rt->hasStd) return;
|
||||
rt->hasStd=true;
|
||||
tobject_t* __fs = tobject_create(rt);
|
||||
__fs->type = tdict;
|
||||
__fs->data.dict= dict_create();
|
||||
tobject_t* __create = tobject_create(rt);
|
||||
__create->type = tdict;
|
||||
__create->data.dict= dict_create();
|
||||
tobject_t* __console = tobject_create(rt);
|
||||
__console->type = tdict;
|
||||
__console->data.dict= dict_create();
|
||||
|
@ -801,8 +855,6 @@ runtime_t* runtime_init()
|
|||
tobject_t* __math = tobject_create(rt);
|
||||
__math->type = tdict;
|
||||
__math->data.dict = dict_create();
|
||||
runtime_create_method_on_dict(__create->data.dict,"array",rt,NULL,__create_array_external_method,NULL);
|
||||
runtime_create_method_on_dict(__create->data.dict,"dict",rt,NULL,__create_dict_external_method,NULL);
|
||||
|
||||
|
||||
runtime_create_method_on_dict(__console->data.dict,"clear",rt,NULL,__console_clear_external_method,NULL);
|
||||
|
@ -860,18 +912,42 @@ runtime_t* runtime_init()
|
|||
rt->globals->setvariable(rt->globals,"fs",__fs);
|
||||
rt->globals->setvariable(rt->globals,"console",__console);
|
||||
rt->globals->setvariable(rt->globals,"math",__math);
|
||||
#if defined(USE_THREADS)
|
||||
runtime_register_threads(rt,__create->data.dict);
|
||||
#endif
|
||||
rt->globals->setvariable(rt->globals,"create",__create);
|
||||
|
||||
rt->globals->setvariable(rt->globals,"reflection",__reflection);
|
||||
|
||||
#if defined(USE_SDL2)
|
||||
runtime_register_sdl2(rt);
|
||||
runtime_register_sdl(rt);
|
||||
#endif
|
||||
#if defined(USE_NETWORK)
|
||||
runtime_register_network(rt);
|
||||
|
||||
#endif
|
||||
#if defined(USE_MBED)
|
||||
runtime_register_mbed(rt);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
runtime_t* runtime_init()
|
||||
{
|
||||
runtime_t* rt = (runtime_t*)malloc(sizeof(runtime_t));
|
||||
rt->hasStd=false;
|
||||
rt->globals = NULL;
|
||||
rt->program=NULL;
|
||||
rt->reg=NULL;
|
||||
list_create(rt,&rt->args,0);
|
||||
scope_create_root(rt);
|
||||
|
||||
tobject_t* __create = tobject_create(rt);
|
||||
__create->type = tdict;
|
||||
__create->data.dict= dict_create();
|
||||
runtime_create_method_on_dict(__create->data.dict,"array",rt,NULL,__create_array_external_method,NULL);
|
||||
runtime_create_method_on_dict(__create->data.dict,"dict",rt,NULL,__create_dict_external_method,NULL);
|
||||
#if defined(USE_THREADS)
|
||||
runtime_register_threads(rt,__create->data.dict);
|
||||
#endif
|
||||
rt->globals->setvariable(rt->globals,"create",__create);
|
||||
|
||||
return rt;
|
||||
}
|
||||
void runtime_add_argument(runtime_t* rt,tobject_t* arg)
|
||||
|
|
|
@ -1,95 +1,793 @@
|
|||
/*
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
#include "tlang.h"
|
||||
#include "FreeMonoBold.h"
|
||||
|
||||
#if defined(USE_SDL2)
|
||||
#include "SDL2/SDL.h"
|
||||
tobject_t* sdl2=NULL;
|
||||
tobject_t* __sdl_init_external_method(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
void __init_sdl(runtime_t* rt,tobject_t* obj)
|
||||
{
|
||||
SDL_Init(SDL_INIT_EVERYTHING);
|
||||
IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG);
|
||||
TTF_Init();
|
||||
}
|
||||
|
||||
if(args->length >= 1 && args->items[0]->type == tnumber)
|
||||
{
|
||||
return tobject_number(rt,SDL_Init((Uint32)args->items[0]->data.number));
|
||||
}
|
||||
return tobject_number(rt,SDL_Init(SDL_INIT_EVERYTHING));
|
||||
}
|
||||
tobject_t* __sdl_renderclear_external_method(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
void tdict_setvalue(tobject_t* obj,const char* key,tobject_t* val)
|
||||
{
|
||||
if(obj->type == tdict)
|
||||
{
|
||||
if(args->length >= 1 && args->items[0]->type == tnumber)
|
||||
{
|
||||
int64_t n = (int64_t)args->items[0]->data.number;
|
||||
return tobject_number(rt,SDL_RenderClear((SDL_Renderer*)(void*)n));
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
kvp_t kvp;
|
||||
kvp.key = key;
|
||||
kvp.value = val;
|
||||
dict_setkvp(obj->data.dict,kvp);
|
||||
}else{
|
||||
tobject_freeifzero(val);
|
||||
}
|
||||
}
|
||||
|
||||
tobject_t* __sdl_renderpresent_external_method(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
bool tdict_getvalue(tobject_t* obj,const char* key,tobject_t** res)
|
||||
{
|
||||
if(obj->type == tdict)
|
||||
{
|
||||
if(args->length >= 1 && args->items[0]->type == tnumber)
|
||||
if(dict_haskey(obj->data.dict,key))
|
||||
{
|
||||
int64_t n = (int64_t)args->items[0]->data.number;
|
||||
SDL_RenderPresent((SDL_Renderer*)(void*)n);
|
||||
*res = dict_getkvp(obj->data.dict,key)->value;
|
||||
return true;
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void SDLColor_SetTobject(runtime_t* rt,tobject_t* obj,SDL_Color* c)
|
||||
{
|
||||
tdict_setvalue(obj,"r",tobject_number(rt,c->r));
|
||||
tdict_setvalue(obj,"g",tobject_number(rt,c->g));
|
||||
tdict_setvalue(obj,"b",tobject_number(rt,c->b));
|
||||
tdict_setvalue(obj,"a",tobject_number(rt,c->a));
|
||||
}
|
||||
void SDLRect_SetTobject(runtime_t* rt,tobject_t* obj,SDL_Rect* rect)
|
||||
{
|
||||
tdict_setvalue(obj,"x",tobject_number(rt,rect->x));
|
||||
tdict_setvalue(obj,"y",tobject_number(rt,rect->y));
|
||||
tdict_setvalue(obj,"w",tobject_number(rt,rect->w));
|
||||
tdict_setvalue(obj,"h",tobject_number(rt,rect->h));
|
||||
}
|
||||
void SDLColor_GetTobject(tobject_t* obj,SDL_Color* color)
|
||||
{
|
||||
color->r = 0;
|
||||
color->g = 0;
|
||||
color->b = 0;
|
||||
color->a = 255;
|
||||
tobject_t* res;
|
||||
if(tdict_getvalue(obj,"r",&res) && res->type == tnumber)
|
||||
{
|
||||
color->r=(Uint8)res->data.number;
|
||||
}
|
||||
if(tdict_getvalue(obj,"g",&res) && res->type == tnumber)
|
||||
{
|
||||
color->g=(Uint8)res->data.number;
|
||||
}
|
||||
if(tdict_getvalue(obj,"b",&res) && res->type == tnumber)
|
||||
{
|
||||
color->b=(Uint8)res->data.number;
|
||||
}
|
||||
if(tdict_getvalue(obj,"a",&res) && res->type == tnumber)
|
||||
{
|
||||
color->a=(Uint8)res->data.number;
|
||||
}
|
||||
}
|
||||
void SDLRect_GetTobject(tobject_t* obj,SDL_Rect* rect)
|
||||
{
|
||||
rect->x = 0;
|
||||
rect->y = 0;
|
||||
rect->w = 0;
|
||||
rect->h = 0;
|
||||
tobject_t* res;
|
||||
if(tdict_getvalue(obj,"x",&res) && res->type == tnumber)
|
||||
{
|
||||
rect->x=(int)res->data.number;
|
||||
}
|
||||
if(tdict_getvalue(obj,"y",&res) && res->type == tnumber)
|
||||
{
|
||||
rect->y=(int)res->data.number;
|
||||
}
|
||||
if(tdict_getvalue(obj,"w",&res) && res->type == tnumber)
|
||||
{
|
||||
rect->w=(int)res->data.number;
|
||||
}
|
||||
if(tdict_getvalue(obj,"h",&res) && res->type == tnumber)
|
||||
{
|
||||
rect->h=(int)res->data.number;
|
||||
}
|
||||
}
|
||||
tobject_t* sdl_ttfRenderTextSolid_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >=3 && args->items[0]->type == tnumber && args->items[1]->type == tstring && args->items[2]->type == tdict)
|
||||
{
|
||||
SDL_Color color;
|
||||
SDLColor_GetTobject(args->items[2],&color);
|
||||
char* text = string_dupp(args->items[1]->data.string);
|
||||
tobject_t* o=tobject_number(rt,(double)(uintptr_t)(void*)TTF_RenderText_Solid((TTF_Font*)(void*)(uintptr_t)args->items[0]->data.number,text,color));
|
||||
free(text);
|
||||
return o;
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
|
||||
}
|
||||
tobject_t* sdl_color_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
//sdl.color(r,g,b,$a)
|
||||
if(args->length >= 3 && args->items[0]->type == tnumber && args->items[1]->type == tnumber && args->items[2]->type == tnumber)
|
||||
{
|
||||
tobject_t* obj = tobject_create(rt);
|
||||
obj->type = tdict;
|
||||
obj->data.dict = dict_create();
|
||||
tdict_setvalue(obj,"r",args->items[0]);
|
||||
tdict_setvalue(obj,"g",args->items[1]);
|
||||
tdict_setvalue(obj,"b",args->items[2]);
|
||||
if(args->length >= 4 && args->items[3]->type == tnumber)
|
||||
tdict_setvalue(obj,"a",args->items[3]);
|
||||
|
||||
return obj;
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_rect_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
//sdl.rect(x,y,w,h)
|
||||
if(args->length >= 4 && args->items[0]->type == tnumber && args->items[1]->type == tnumber && args->items[2]->type == tnumber && args->items[3]->type == tnumber)
|
||||
{
|
||||
tobject_t* obj = tobject_create(rt);
|
||||
obj->type = tdict;
|
||||
obj->data.dict = dict_create();
|
||||
tdict_setvalue(obj,"x",args->items[0]);
|
||||
tdict_setvalue(obj,"y",args->items[1]);
|
||||
tdict_setvalue(obj,"w",args->items[2]);
|
||||
tdict_setvalue(obj,"h",args->items[3]);
|
||||
return obj;
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_ttfMonoBold_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
|
||||
|
||||
tobject_t* __sdl_destroywindow_external_method(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
if(args->length >= 1 && args->items[0]->type == tnumber)
|
||||
{
|
||||
if(args->length >= 1 && args->items[0]->type == tnumber)
|
||||
{
|
||||
int64_t n = (int64_t)args->items[0]->data.number;
|
||||
SDL_DestroyWindow((SDL_Window*)(void*)n);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
SDL_RWops* pFontMem = SDL_RWFromConstMem(FreeMonoBold, sizeof(FreeMonoBold));
|
||||
return tobject_number(rt,(double)(uintptr_t)(void*)TTF_OpenFontRW(pFontMem,1,args->items[0]->data.number));
|
||||
}
|
||||
tobject_t* __sdl_setrendererdrawcolor_external_method(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_fillRect_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 3 && args->items[0]->type == tnumber && args->items[1]->type == tdict && args->items[2]->type == tnumber)
|
||||
{
|
||||
if(args->length >= 5 && args->items[0]->type == tnumber && args->items[1]->type == tnumber && args->items[2]->type == tnumber && args->items[3]->type == tnumber && args->items[4]->type == tnumber)
|
||||
{
|
||||
int64_t n = (int64_t)args->items[0]->data.number;
|
||||
return tobject_number(rt,SDL_SetRenderDrawColor((SDL_Renderer*)(void*)n,(Uint8)args->items[1]->data.number,(Uint8)args->items[2]->data.number,(Uint8)args->items[3]->data.number,(Uint8)args->items[4]->data.number));
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
SDL_Rect rect;
|
||||
SDLRect_GetTobject(args->items[1],&rect);
|
||||
return tobject_number(rt,SDL_FillRect((SDL_Surface*)(void*)(uintptr_t)args->items[0]->data.number,&rect,(Uint32)args->items[2]->data.number ));
|
||||
}
|
||||
tobject_t* __sdl_createrenderer_external_method(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
return tobject_basic(rt,tnull);
|
||||
|
||||
if(args->length >= 3 && args->items[0]->type == tnumber && args->items[1]->type == tnumber&& args->items[2]->type == tnumber)
|
||||
{
|
||||
int64_t n = (int64_t)args->items[0]->data.number;
|
||||
SDL_Renderer* r=SDL_CreateRenderer((SDL_Window*)(void*)n,(int)args->items[1]->data.number,(Uint32)args->items[2]->data.number);
|
||||
|
||||
return tobject_number(rt,(double)(int64_t)r);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* __sdl_createwindow_external_method(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
}
|
||||
tobject_t* sdl_renderFillRect_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >=2 && args->items[0]->type == tnumber && args->items[1]->type == tdict)
|
||||
{
|
||||
if(args->length >= 6 && args->items[0]->type == tstring && args->items[1]->type == tnumber&& args->items[2]->type == tnumber&& args->items[3]->type == tnumber&& args->items[4]->type == tnumber&& args->items[5]->type == tnumber)
|
||||
{
|
||||
char* name = string_dupp(args->items[0]->data.string);
|
||||
SDL_Window* w=SDL_CreateWindow(name,(int)args->items[1]->data.number,(int)args->items[2]->data.number,(int)args->items[3]->data.number,(int)args->items[4]->data.number,(Uint32)args->items[5]->data.number);
|
||||
free(name);
|
||||
return tobject_number(rt,(double)(int64_t)w);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
SDL_Rect rect;
|
||||
SDLRect_GetTobject(args->items[1],&rect);
|
||||
return tobject_number(rt,SDL_RenderFillRect((SDL_Renderer*)(void*)(uintptr_t)args->items[0]->data.number,&rect ));
|
||||
}
|
||||
void runtime_register_sdl2(runtime_t* rt)
|
||||
{
|
||||
if(sdl2 == NULL)
|
||||
{
|
||||
sdl2 = tobject_create(rt);
|
||||
sdl2->type = tdict;
|
||||
sdl2->data.dict = dict_create();
|
||||
runtime_create_method_on_dict(sdl2->data.dict,"destroyWindow",rt,NULL,__sdl_destroywindow_external_method,NULL);
|
||||
runtime_create_method_on_dict(sdl2->data.dict,"createRenderer",rt,NULL,__sdl_createrenderer_external_method,NULL);
|
||||
runtime_create_method_on_dict(sdl2->data.dict,"setRenderDrawColor",rt,NULL,__sdl_setrendererdrawcolor_external_method,NULL);
|
||||
runtime_create_method_on_dict(sdl2->data.dict,"renderClear",rt,NULL,__sdl_renderclear_external_method,NULL);
|
||||
runtime_create_method_on_dict(sdl2->data.dict,"renderPresent",rt,NULL,__sdl_renderpresent_external_method,NULL);
|
||||
return tobject_basic(rt,tnull);
|
||||
|
||||
runtime_create_method_on_dict(sdl2->data.dict,"createWindow",rt,NULL,__sdl_createwindow_external_method,NULL);
|
||||
runtime_create_method_on_dict(sdl2->data.dict,"init",rt,NULL,__sdl_init_external_method,NULL);
|
||||
}
|
||||
tobject_t* sdl_renderCopy_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >=3 && args->items[0]->type == tnumber && args->items[1]->type == tnumber && (args->items[2]->type == tdict || args->items[2]->type == tnull) && (args->items[3]->type == tdict || args->items[3]->type == tnull))
|
||||
{
|
||||
SDL_Rect src;
|
||||
SDL_Rect dest;
|
||||
SDL_Rect* srcPtr = &src;
|
||||
SDL_Rect* destPtr = &dest;
|
||||
|
||||
if( args->items[2]->type == tnull)
|
||||
{
|
||||
srcPtr = NULL;
|
||||
}else{
|
||||
SDLRect_GetTobject(args->items[2],srcPtr);
|
||||
}
|
||||
rt->globals->setvariable(rt->globals,"sdl",sdl2);
|
||||
if( args->items[3]->type == tnull)
|
||||
{
|
||||
destPtr = NULL;
|
||||
}else{
|
||||
SDLRect_GetTobject(args->items[3],destPtr);
|
||||
}
|
||||
return tobject_number(rt, SDL_RenderCopy((SDL_Renderer*)(void*)(uintptr_t)args->items[0]->data.number,
|
||||
(SDL_Texture*)(void*)(uintptr_t)args->items[1]->data.number,
|
||||
srcPtr,
|
||||
destPtr));
|
||||
}
|
||||
#endif
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_acos_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && (args->items[0]->type == tnumber || args->items[0]->type == tnull))
|
||||
{
|
||||
double _arg0 = (double)args->items[0]->data.number;
|
||||
double _res = (double)SDL_acos(_arg0);
|
||||
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_audioInit_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && args->items[0]->type == tstring)
|
||||
{
|
||||
char* _arg0 = (char*)string_dupp(args->items[0]->data.string);
|
||||
double _res = (double)SDL_AudioInit(_arg0);
|
||||
free(_arg0);
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_audioQuit_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 0)
|
||||
{
|
||||
SDL_AudioQuit();
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_audioStreamAvailable_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && (args->items[0]->type == tnumber || args->items[0]->type == tnull))
|
||||
{
|
||||
SDL_AudioStream* _arg0 = (SDL_AudioStream*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
double _res = (double)SDL_AudioStreamAvailable(_arg0);
|
||||
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_audioStreamClear_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && (args->items[0]->type == tnumber || args->items[0]->type == tnull))
|
||||
{
|
||||
SDL_AudioStream* _arg0 = (SDL_AudioStream*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
SDL_AudioStreamClear(_arg0);
|
||||
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_audioStreamFlush_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && (args->items[0]->type == tnumber || args->items[0]->type == tnull))
|
||||
{
|
||||
SDL_AudioStream* _arg0 = (SDL_AudioStream*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
double _res = (double)SDL_AudioStreamFlush(_arg0);
|
||||
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_captureMouse_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && args->items[0]->type == tbool)
|
||||
{
|
||||
SDL_bool _arg0 = (SDL_bool)args->items[0]->data.boolean;
|
||||
double _res = (double)SDL_CaptureMouse(_arg0);
|
||||
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_clearError_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 0)
|
||||
{
|
||||
SDL_ClearError();
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_clearHints_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 0)
|
||||
{
|
||||
SDL_ClearHints();
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_clearQueuedAudio_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && (args->items[0]->type == tnumber || args->items[0]->type == tnull))
|
||||
{
|
||||
SDL_AudioDeviceID _arg0 = (SDL_AudioDeviceID)args->items[0]->data.number;
|
||||
SDL_ClearQueuedAudio(_arg0);
|
||||
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_closeAudio_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 0)
|
||||
{
|
||||
SDL_CloseAudio();
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_closeAudioDevice_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && (args->items[0]->type == tnumber || args->items[0]->type == tnull))
|
||||
{
|
||||
SDL_AudioDeviceID _arg0 = (SDL_AudioDeviceID)args->items[0]->data.number;
|
||||
SDL_CloseAudioDevice(_arg0);
|
||||
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_compilerBarrier_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 0)
|
||||
{
|
||||
SDL_CompilerBarrier();
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_createRenderer_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 3 && (args->items[0]->type == tnumber || args->items[0]->type == tnull) && (args->items[1]->type == tnumber || args->items[1]->type == tnull) && (args->items[2]->type == tnumber || args->items[2]->type == tnull))
|
||||
{
|
||||
SDL_Window* _arg0 = (SDL_Window*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
int _arg1 = (int)args->items[1]->data.number;
|
||||
Uint32 _arg2 = (Uint32)args->items[2]->data.number;
|
||||
double _res = (double)(uintptr_t)(void*)SDL_CreateRenderer(_arg0,_arg1,_arg2);
|
||||
|
||||
|
||||
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_createRGBSurface_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 8 && (args->items[0]->type == tnumber || args->items[0]->type == tnull) && (args->items[1]->type == tnumber || args->items[1]->type == tnull) && (args->items[2]->type == tnumber || args->items[2]->type == tnull) && (args->items[3]->type == tnumber || args->items[3]->type == tnull) && (args->items[4]->type == tnumber || args->items[4]->type == tnull) && (args->items[5]->type == tnumber || args->items[5]->type == tnull) && (args->items[6]->type == tnumber || args->items[6]->type == tnull) && (args->items[7]->type == tnumber || args->items[7]->type == tnull))
|
||||
{
|
||||
Uint32 _arg0 = (Uint32)args->items[0]->data.number;
|
||||
int _arg1 = (int)args->items[1]->data.number;
|
||||
int _arg2 = (int)args->items[2]->data.number;
|
||||
int _arg3 = (int)args->items[3]->data.number;
|
||||
Uint32 _arg4 = (Uint32)args->items[4]->data.number;
|
||||
Uint32 _arg5 = (Uint32)args->items[5]->data.number;
|
||||
Uint32 _arg6 = (Uint32)args->items[6]->data.number;
|
||||
Uint32 _arg7 = (Uint32)args->items[7]->data.number;
|
||||
double _res = (double)(uintptr_t)(void*)SDL_CreateRGBSurface(_arg0,_arg1,_arg2,_arg3,_arg4,_arg5,_arg6,_arg7);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_createRGBSurfaceWithFormat_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 5 && (args->items[0]->type == tnumber || args->items[0]->type == tnull) && (args->items[1]->type == tnumber || args->items[1]->type == tnull) && (args->items[2]->type == tnumber || args->items[2]->type == tnull) && (args->items[3]->type == tnumber || args->items[3]->type == tnull) && (args->items[4]->type == tnumber || args->items[4]->type == tnull))
|
||||
{
|
||||
Uint32 _arg0 = (Uint32)args->items[0]->data.number;
|
||||
int _arg1 = (int)args->items[1]->data.number;
|
||||
int _arg2 = (int)args->items[2]->data.number;
|
||||
int _arg3 = (int)args->items[3]->data.number;
|
||||
Uint32 _arg4 = (Uint32)args->items[4]->data.number;
|
||||
double _res = (double)(uintptr_t)(void*)SDL_CreateRGBSurfaceWithFormat(_arg0,_arg1,_arg2,_arg3,_arg4);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_createShapedWindow_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 6 && args->items[0]->type == tstring && (args->items[1]->type == tnumber || args->items[1]->type == tnull) && (args->items[2]->type == tnumber || args->items[2]->type == tnull) && (args->items[3]->type == tnumber || args->items[3]->type == tnull) && (args->items[4]->type == tnumber || args->items[4]->type == tnull) && (args->items[5]->type == tnumber || args->items[5]->type == tnull))
|
||||
{
|
||||
char* _arg0 = (char*)string_dupp(args->items[0]->data.string);
|
||||
int _arg1 = (int)args->items[1]->data.number;
|
||||
int _arg2 = (int)args->items[2]->data.number;
|
||||
int _arg3 = (int)args->items[3]->data.number;
|
||||
int _arg4 = (int)args->items[4]->data.number;
|
||||
Uint32 _arg5 = (Uint32)args->items[5]->data.number;
|
||||
double _res = (double)(uintptr_t)(void*)SDL_CreateShapedWindow(_arg0,_arg1,_arg2,_arg3,_arg4,_arg5);
|
||||
free(_arg0);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_createSoftwareRenderer_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && (args->items[0]->type == tnumber || args->items[0]->type == tnull))
|
||||
{
|
||||
SDL_Surface* _arg0 = (SDL_Surface*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
double _res = (double)(uintptr_t)(void*)SDL_CreateSoftwareRenderer(_arg0);
|
||||
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_createSystemCursor_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && (args->items[0]->type == tnumber || args->items[0]->type == tnull))
|
||||
{
|
||||
SDL_SystemCursor _arg0 = (SDL_SystemCursor)args->items[0]->data.number;
|
||||
double _res = (double)(uintptr_t)(void*)SDL_CreateSystemCursor(_arg0);
|
||||
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_createWindow_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 6 && args->items[0]->type == tstring && (args->items[1]->type == tnumber || args->items[1]->type == tnull) && (args->items[2]->type == tnumber || args->items[2]->type == tnull) && (args->items[3]->type == tnumber || args->items[3]->type == tnull) && (args->items[4]->type == tnumber || args->items[4]->type == tnull) && (args->items[5]->type == tnumber || args->items[5]->type == tnull))
|
||||
{
|
||||
char* _arg0 = (char*)string_dupp(args->items[0]->data.string);
|
||||
int _arg1 = (int)args->items[1]->data.number;
|
||||
int _arg2 = (int)args->items[2]->data.number;
|
||||
int _arg3 = (int)args->items[3]->data.number;
|
||||
int _arg4 = (int)args->items[4]->data.number;
|
||||
Uint32 _arg5 = (Uint32)args->items[5]->data.number;
|
||||
double _res = (double)(uintptr_t)(void*)SDL_CreateWindow(_arg0,_arg1,_arg2,_arg3,_arg4,_arg5);
|
||||
free(_arg0);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_delay_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && (args->items[0]->type == tnumber || args->items[0]->type == tnull))
|
||||
{
|
||||
Uint32 _arg0 = (Uint32)args->items[0]->data.number;
|
||||
SDL_Delay(_arg0);
|
||||
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_destroyRenderer_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && (args->items[0]->type == tnumber || args->items[0]->type == tnull))
|
||||
{
|
||||
SDL_Renderer* _arg0 = (SDL_Renderer*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
SDL_DestroyRenderer(_arg0);
|
||||
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_destroyTexture_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && (args->items[0]->type == tnumber || args->items[0]->type == tnull))
|
||||
{
|
||||
SDL_Texture* _arg0 = (SDL_Texture*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
SDL_DestroyTexture(_arg0);
|
||||
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_destroyWindow_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && (args->items[0]->type == tnumber || args->items[0]->type == tnull))
|
||||
{
|
||||
SDL_Window* _arg0 = (SDL_Window*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
SDL_DestroyWindow(_arg0);
|
||||
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_getClipboardText_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 0)
|
||||
{
|
||||
char* _res = (char*)SDL_GetClipboardText();
|
||||
string_t* _ress=string_create();
|
||||
string_appendp(_ress,_res);
|
||||
free(_res);
|
||||
return tobject_string(rt,_ress);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_imgLoad_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && args->items[0]->type == tstring)
|
||||
{
|
||||
char* _arg0 = (char*)string_dupp(args->items[0]->data.string);
|
||||
double _res = (double)(uintptr_t)(void*)IMG_Load(_arg0);
|
||||
free(_arg0);
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_renderDrawPoint_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 3 && (args->items[0]->type == tnumber || args->items[0]->type == tnull) && (args->items[1]->type == tnumber || args->items[1]->type == tnull) && (args->items[2]->type == tnumber || args->items[2]->type == tnull))
|
||||
{
|
||||
SDL_Renderer* _arg0 = (SDL_Renderer*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
int _arg1 = (int)args->items[1]->data.number;
|
||||
int _arg2 = (int)args->items[2]->data.number;
|
||||
double _res = (double)SDL_RenderDrawPoint(_arg0,_arg1,_arg2);
|
||||
|
||||
|
||||
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_renderFlush_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && (args->items[0]->type == tnumber || args->items[0]->type == tnull))
|
||||
{
|
||||
SDL_Renderer* _arg0 = (SDL_Renderer*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
double _res = (double)SDL_RenderFlush(_arg0);
|
||||
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_renderPresent_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && (args->items[0]->type == tnumber || args->items[0]->type == tnull))
|
||||
{
|
||||
SDL_Renderer* _arg0 = (SDL_Renderer*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
SDL_RenderPresent(_arg0);
|
||||
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_restoreWindow_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && (args->items[0]->type == tnumber || args->items[0]->type == tnull))
|
||||
{
|
||||
SDL_Window* _arg0 = (SDL_Window*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
SDL_RestoreWindow(_arg0);
|
||||
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_saveBMP_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 2 && (args->items[0]->type == tnumber || args->items[0]->type == tnull) && args->items[1]->type == tstring)
|
||||
{
|
||||
SDL_Surface* _arg0 = (SDL_Surface*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
char* _arg1 = (char*)string_dupp(args->items[1]->data.string);
|
||||
double _res = (double)SDL_SaveBMP(_arg0,_arg1);
|
||||
|
||||
free(_arg1);
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_setWindowResizable_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 2 && (args->items[0]->type == tnumber || args->items[0]->type == tnull) && args->items[1]->type == tbool)
|
||||
{
|
||||
SDL_Window* _arg0 = (SDL_Window*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
SDL_bool _arg1 = (SDL_bool)args->items[1]->data.boolean;
|
||||
SDL_SetWindowResizable(_arg0,_arg1);
|
||||
|
||||
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_setWindowTitle_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 2 && (args->items[0]->type == tnumber || args->items[0]->type == tnull) && args->items[1]->type == tstring)
|
||||
{
|
||||
SDL_Window* _arg0 = (SDL_Window*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
char* _arg1 = (char*)string_dupp(args->items[1]->data.string);
|
||||
SDL_SetWindowTitle(_arg0,_arg1);
|
||||
|
||||
free(_arg1);
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_showWindow_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && (args->items[0]->type == tnumber || args->items[0]->type == tnull))
|
||||
{
|
||||
SDL_Window* _arg0 = (SDL_Window*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
SDL_ShowWindow(_arg0);
|
||||
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_setWindowSize_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 3 && (args->items[0]->type == tnumber || args->items[0]->type == tnull) && (args->items[1]->type == tnumber || args->items[1]->type == tnull) && (args->items[2]->type == tnumber || args->items[2]->type == tnull))
|
||||
{
|
||||
SDL_Window* _arg0 = (SDL_Window*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
int _arg1 = (int)args->items[1]->data.number;
|
||||
int _arg2 = (int)args->items[2]->data.number;
|
||||
SDL_SetWindowSize(_arg0,_arg1,_arg2);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_setRenderDrawColor_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 5 && (args->items[0]->type == tnumber || args->items[0]->type == tnull) && (args->items[1]->type == tnumber || args->items[1]->type == tnull) && (args->items[2]->type == tnumber || args->items[2]->type == tnull) && (args->items[3]->type == tnumber || args->items[3]->type == tnull) && (args->items[4]->type == tnumber || args->items[4]->type == tnull))
|
||||
{
|
||||
SDL_Renderer* _arg0 = (SDL_Renderer*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
Uint8 _arg1 = (Uint8)args->items[1]->data.number;
|
||||
Uint8 _arg2 = (Uint8)args->items[2]->data.number;
|
||||
Uint8 _arg3 = (Uint8)args->items[3]->data.number;
|
||||
Uint8 _arg4 = (Uint8)args->items[4]->data.number;
|
||||
double _res = (double)SDL_SetRenderDrawColor(_arg0,_arg1,_arg2,_arg3,_arg4);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_renderDrawLine_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 5 && (args->items[0]->type == tnumber || args->items[0]->type == tnull) && (args->items[1]->type == tnumber || args->items[1]->type == tnull) && (args->items[2]->type == tnumber || args->items[2]->type == tnull) && (args->items[3]->type == tnumber || args->items[3]->type == tnull) && (args->items[4]->type == tnumber || args->items[4]->type == tnull))
|
||||
{
|
||||
SDL_Renderer* _arg0 = (SDL_Renderer*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
int _arg1 = (int)args->items[1]->data.number;
|
||||
int _arg2 = (int)args->items[2]->data.number;
|
||||
int _arg3 = (int)args->items[3]->data.number;
|
||||
int _arg4 = (int)args->items[4]->data.number;
|
||||
double _res = (double)SDL_RenderDrawLine(_arg0,_arg1,_arg2,_arg3,_arg4);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_renderClear_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && (args->items[0]->type == tnumber || args->items[0]->type == tnull))
|
||||
{
|
||||
SDL_Renderer* _arg0 = (SDL_Renderer*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
double _res = (double)SDL_RenderClear(_arg0);
|
||||
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_setClipboardText_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && args->items[0]->type == tstring)
|
||||
{
|
||||
char* _arg0 = (char*)string_dupp(args->items[0]->data.string);
|
||||
double _res = (double)SDL_SetClipboardText(_arg0);
|
||||
free(_arg0);
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_createTextureFromSurface_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 2 && (args->items[0]->type == tnumber || args->items[0]->type == tnull) && (args->items[1]->type == tnumber || args->items[1]->type == tnull))
|
||||
{
|
||||
SDL_Renderer* _arg0 = (SDL_Renderer*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
SDL_Surface* _arg1 = (SDL_Surface*)(void*)(uintptr_t)args->items[1]->data.number;
|
||||
double _res = (double)(uintptr_t)(void*)SDL_CreateTextureFromSurface(_arg0,_arg1);
|
||||
|
||||
|
||||
return tobject_number(rt,_res);
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* sdl_ttfCloseFont_external_function(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 1 && (args->items[0]->type == tnumber || args->items[0]->type == tnull))
|
||||
{
|
||||
TTF_Font* _arg0 = (TTF_Font*)(void*)(uintptr_t)args->items[0]->data.number;
|
||||
TTF_CloseFont(_arg0);
|
||||
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
|
||||
void runtime_register_sdl(runtime_t* rt)
|
||||
{
|
||||
tobject_t* _sdl = tobject_create(rt);
|
||||
_sdl->type = tdict;
|
||||
_sdl->data.dict = dict_create();
|
||||
__init_sdl(rt,_sdl);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"acos",rt,NULL,sdl_acos_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"audioInit",rt,NULL,sdl_audioInit_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"audioQuit",rt,NULL,sdl_audioQuit_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"audioStreamAvailable",rt,NULL,sdl_audioStreamAvailable_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"audioStreamClear",rt,NULL,sdl_audioStreamClear_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"audioStreamFlush",rt,NULL,sdl_audioStreamFlush_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"captureMouse",rt,NULL,sdl_captureMouse_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"clearError",rt,NULL,sdl_clearError_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"clearHints",rt,NULL,sdl_clearHints_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"clearQueuedAudio",rt,NULL,sdl_clearQueuedAudio_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"closeAudio",rt,NULL,sdl_closeAudio_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"closeAudioDevice",rt,NULL,sdl_closeAudioDevice_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"compilerBarrier",rt,NULL,sdl_compilerBarrier_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"createRenderer",rt,NULL,sdl_createRenderer_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"createRGBSurface",rt,NULL,sdl_createRGBSurface_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"createRGBSurfaceWithFormat",rt,NULL,sdl_createRGBSurfaceWithFormat_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"createShapedWindow",rt,NULL,sdl_createShapedWindow_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"createSoftwareRenderer",rt,NULL,sdl_createSoftwareRenderer_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"createSystemCursor",rt,NULL,sdl_createSystemCursor_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"createWindow",rt,NULL,sdl_createWindow_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"delay",rt,NULL,sdl_delay_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"destroyRenderer",rt,NULL,sdl_destroyRenderer_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"destroyTexture",rt,NULL,sdl_destroyTexture_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"destroyWindow",rt,NULL,sdl_destroyWindow_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"getClipboardText",rt,NULL,sdl_getClipboardText_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"imgLoad",rt,NULL,sdl_imgLoad_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"renderDrawPoint",rt,NULL,sdl_renderDrawPoint_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"renderFlush",rt,NULL,sdl_renderFlush_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"renderPresent",rt,NULL,sdl_renderPresent_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"restoreWindow",rt,NULL,sdl_restoreWindow_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"saveBMP",rt,NULL,sdl_saveBMP_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"setWindowResizable",rt,NULL,sdl_setWindowResizable_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"setWindowTitle",rt,NULL,sdl_setWindowTitle_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"showWindow",rt,NULL,sdl_showWindow_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"setWindowSize",rt,NULL,sdl_setWindowSize_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"setRenderDrawColor",rt,NULL,sdl_setRenderDrawColor_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"renderDrawLine",rt,NULL,sdl_renderDrawLine_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"renderClear",rt,NULL,sdl_renderClear_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"setClipboardText",rt,NULL,sdl_setClipboardText_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"createTextureFromSurface",rt,NULL,sdl_createTextureFromSurface_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"ttfCloseFont",rt,NULL,sdl_ttfCloseFont_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"fillRect",rt,NULL,sdl_fillRect_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"renderFillRect",rt,NULL,sdl_renderFillRect_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"renderCopy",rt,NULL,sdl_renderCopy_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"ttfRenderTextSolid",rt,NULL,sdl_ttfRenderTextSolid_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"ttfMonoBold",rt,NULL,sdl_ttfMonoBold_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"rect",rt,NULL,sdl_rect_external_function,NULL);
|
||||
runtime_create_method_on_dict(_sdl->data.dict,"color",rt,NULL,sdl_color_external_function,NULL);
|
||||
kvp_t kvp_WINDOWPOS_CENTERED;
|
||||
kvp_WINDOWPOS_CENTERED.key = "WINDOWPOS_CENTERED";
|
||||
kvp_WINDOWPOS_CENTERED.value = tobject_number(rt,SDL_WINDOWPOS_CENTERED);
|
||||
dict_setkvp(_sdl->data.dict,kvp_WINDOWPOS_CENTERED);
|
||||
|
||||
rt->globals->setvariable(rt->globals,"sdl",_sdl);
|
||||
}
|
||||
*/
|
|
@ -1,221 +1,75 @@
|
|||
#if defined(HW_RVL)
|
||||
#include "tlang.h"
|
||||
#include <wiiuse/wpad.h>
|
||||
#include <ogcsys.h>
|
||||
#include <stdio.h>
|
||||
|
||||
tobject_t* wpad=NULL;
|
||||
bool init=false;
|
||||
struct {
|
||||
list_tobject_t down_handler;
|
||||
list_tobject_t up_handler;
|
||||
} wpad_data[4];
|
||||
|
||||
typedef struct {
|
||||
tobject_t* obj;
|
||||
int chan;
|
||||
} eventctx_t;
|
||||
|
||||
int* channels = {WPAD_CHAN_0,WPAD_CHAN_1,WPAD_CHAN_2,WPAD_CHAN_3};
|
||||
tobject_t* __wpad_get_buttons_down_external_method(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
u32 b = WPAD_ButtonsDown(*((int*)ptr));
|
||||
return tobject_number(rt,b);
|
||||
}
|
||||
void __free_eventctx(tobject_t* o)
|
||||
{
|
||||
free(o->data.external_method.data);
|
||||
}
|
||||
|
||||
tobject_t* __wpad_get_buttons_up_external_method(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
u32 b = WPAD_ButtonsUp(*((int*)ptr));
|
||||
return tobject_number(rt,b);
|
||||
}
|
||||
tobject_t* __wpad_init_external_method(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
|
||||
if(!init)
|
||||
{
|
||||
int i;
|
||||
for(i = 0;i<4;i++){
|
||||
list_create(rt,&wpad_data[i].down_handler,0);
|
||||
list_create(rt,&wpad_data[i].up_handler,0);
|
||||
}
|
||||
init = true;
|
||||
return tobject_number(rt,WPAD_Init());
|
||||
}
|
||||
}
|
||||
tobject_t* __wpad_remove_up_handler(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 0)
|
||||
{
|
||||
eventctx_t* ctx = (eventctx_t*)ptr;
|
||||
|
||||
list_remove(&wpad_data[ctx->chan].up_handler,args->items[0]);
|
||||
return ctx->obj;
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* __wpad_add_up_handler(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 0)
|
||||
{
|
||||
eventctx_t* ctx = (eventctx_t*)ptr;
|
||||
|
||||
list_add(&wpad_data[ctx->chan].up_handler,args->items[0]);
|
||||
return ctx->obj;
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* __wpad_remove_down_handler(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 0)
|
||||
{
|
||||
eventctx_t* ctx = (eventctx_t*)ptr;
|
||||
|
||||
list_remove(&wpad_data[ctx->chan].down_handler,args->items[0]);
|
||||
return ctx->obj;
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* __wpad_add_down_handler(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
if(args->length >= 0)
|
||||
{
|
||||
eventctx_t* ctx = (eventctx_t*)ptr;
|
||||
|
||||
list_add(&wpad_data[ctx->chan].down_handler,args->items[0]);
|
||||
return ctx->obj;
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
void wpad_send_up_command(runtime_t* rt)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<4;i++)
|
||||
{
|
||||
tobject_t* o = tobject_create(rt);
|
||||
o->type = tdict;
|
||||
o->data.dict = dict_create();
|
||||
kvp_t kvp0;
|
||||
kvp0.key = "channel";
|
||||
kvp0.value = tobject_number(rt,i);
|
||||
dict_setkvp(o->data.dict,kvp0);
|
||||
kvp0.key = "buttons";
|
||||
kvp0.value = tobject_number(rt,WPAD_ButtonsUp(i));
|
||||
dict_setkvp(o->data.dict,kvp0);
|
||||
int j;
|
||||
list_tobject_t myArgs;
|
||||
list_add(&myArgs,wpad);
|
||||
list_add(&myArgs,o);
|
||||
for(j=0;j<wpad_data[i].up_handler.length;i++)
|
||||
{
|
||||
tobject_t* res=wpad_data[i].up_handler.items[j];
|
||||
if(res->type == texternalmethod || res->type == tinternalmethod)
|
||||
{
|
||||
|
||||
tobject_call(rt->globals,res,&myArgs);
|
||||
}
|
||||
}
|
||||
list_free(&myArgs);
|
||||
}
|
||||
}
|
||||
void wpad_send_down_command(runtime_t* rt)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<4;i++)
|
||||
{
|
||||
tobject_t* o = tobject_create(rt);
|
||||
o->type = tdict;
|
||||
o->data.dict = dict_create();
|
||||
kvp_t kvp0;
|
||||
kvp0.key = "channel";
|
||||
kvp0.value = tobject_number(rt,i);
|
||||
dict_setkvp(o->data.dict,kvp0);
|
||||
kvp0.key = "buttons";
|
||||
kvp0.value = tobject_number(rt,WPAD_ButtonsDown(i));
|
||||
dict_setkvp(o->data.dict,kvp0);
|
||||
int j;
|
||||
list_tobject_t myArgs;
|
||||
list_add(&myArgs,wpad);
|
||||
list_add(&myArgs,o);
|
||||
for(j=0;j<wpad_data[i].down_handler.length;i++)
|
||||
{
|
||||
tobject_t* res=wpad_data[i].down_handler.items[j];
|
||||
if(res->type == texternalmethod || res->type == tinternalmethod)
|
||||
{
|
||||
|
||||
tobject_call(rt->globals,res,&myArgs);
|
||||
}
|
||||
}
|
||||
list_free(&myArgs);
|
||||
}
|
||||
}
|
||||
tobject_t* __wpad_scanpads_external_method(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
s32 s =WPAD_ScanPads();
|
||||
|
||||
wpad_send_down_command(rt);
|
||||
wpad_send_up_command(rt);
|
||||
|
||||
return tobject_number(rt,s);
|
||||
}
|
||||
tobject_t* __wpad_at_external_method(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
tobject_t* __wpad_buttonsdown_external_method(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
//at(i)
|
||||
|
||||
if(args->length > 0 && args->items[0]->type == tnumber && args->items[0]->data.number >= 0 && args->items[0]->data.number < 4)
|
||||
{
|
||||
tobject_t* wpad_chan = tobject_create(rt);
|
||||
wpad_chan->type = tdict;
|
||||
wpad_chan->data.dict = dict_create();
|
||||
runtime_create_method_on_dict(wpad->data.dict,"getbuttonsdown",rt,&channels[(int)args->items[0]->data.number],__wpad_get_buttons_down_external_method,NULL);
|
||||
runtime_create_method_on_dict(wpad->data.dict,"getbuttonsup",rt,&channels[(int)args->items[0]->data.number],__wpad_get_buttons_up_external_method,NULL);
|
||||
return tobject_number(rt,WPAD_ButtonsDown((int)args->items[0]->data.number));
|
||||
|
||||
tobject_t* downEvent = tobject_create(rt);
|
||||
downEvent->type = tdict;
|
||||
downEvent->data.dict = dict_create();
|
||||
tobject_t* upEvent = tobject_create(rt);
|
||||
upEvent->type = tdict;
|
||||
upEvent->data.dict = dict_create();
|
||||
eventctx_t* addObjDown = (eventctx_t*)malloc(sizeof(eventctx_t));
|
||||
addObjDown->chan = (int)args->items[0]->data.number;
|
||||
addObjDown->obj = downEvent;
|
||||
eventctx_t* subObjDown = (eventctx_t*)malloc(sizeof(eventctx_t));
|
||||
subObjDown->chan = (int)args->items[0]->data.number;
|
||||
subObjDown->obj = downEvent;
|
||||
eventctx_t* addObjUp = (eventctx_t*)malloc(sizeof(eventctx_t));
|
||||
addObjUp->chan = (int)args->items[0]->data.number;
|
||||
addObjUp->obj = upEvent;
|
||||
eventctx_t* subObjUp = (eventctx_t*)malloc(sizeof(eventctx_t));
|
||||
subObjDown->chan = (int)args->items[0]->data.number;
|
||||
subObjUp->obj = upEvent;
|
||||
runtime_create_method_on_dict(downEvent->data.dict,"add",rt,addObjDown,__wpad_add_down_handler,__free_eventctx);
|
||||
runtime_create_method_on_dict(downEvent->data.dict,"sub",rt,subObjDown,__wpad_remove_down_handler,__free_eventctx);
|
||||
|
||||
runtime_create_method_on_dict(upEvent->data.dict,"add",rt,addObjUp,__wpad_add_up_handler,__free_eventctx);
|
||||
runtime_create_method_on_dict(upEvent->data.dict,"sub",rt,subObjUp,__wpad_remove_up_handler,__free_eventctx);
|
||||
kvp_t kvp;
|
||||
kvp.key = "down";
|
||||
kvp.value = downEvent;
|
||||
dict_setkvp(wpad_chan->data.dict,kvp);
|
||||
kvp.key = "up";
|
||||
kvp.value = upEvent;
|
||||
dict_setkvp(wpad_chan->data.dict,kvp);
|
||||
|
||||
return wpad_chan;
|
||||
}
|
||||
return tobject_basic(rt,tundef);
|
||||
return tobject_basic(rt,tnull);
|
||||
}
|
||||
tobject_t* __wpad_buttonsup_external_method(runtime_t* rt,void* ptr,list_tobject_t* args)
|
||||
{
|
||||
|
||||
if(args->length > 0 && args->items[0]->type == tnumber && args->items[0]->data.number >= 0 && args->items[0]->data.number < 4)
|
||||
{
|
||||
return tobject_number(rt,WPAD_ButtonsUp((int)args->items[0]->data.number));
|
||||
|
||||
}
|
||||
return tobject_basic(rt,tnull);
|
||||
|
||||
}
|
||||
void __reg_wpad(runtime_t* rt)
|
||||
{
|
||||
printf("Ready to Register WPAD\n");
|
||||
if(wpad ==NULL){
|
||||
wpad = tobject_create(rt);
|
||||
wpad->type = tdict;
|
||||
wpad->data.dict = dict_create();
|
||||
wpad->count = 1;
|
||||
runtime_create_method_on_dict(wpad->data.dict,"init",rt,NULL,__wpad_init_external_method,NULL);
|
||||
runtime_create_method_on_dict(wpad->data.dict,"scanpads",rt,NULL,__wpad_scanpads_external_method,NULL);
|
||||
runtime_create_method_on_dict(wpad->data.dict,"at",rt,NULL,__wpad_at_external_method,NULL);
|
||||
runtime_create_method_on_object(wpad,"init",rt,NULL,__wpad_init_external_method,NULL);
|
||||
runtime_create_method_on_object(wpad,"scanpads",rt,NULL,__wpad_scanpads_external_method,NULL);
|
||||
runtime_create_method_on_object(wpad,"buttonsdown",rt,NULL,__wpad_buttonsdown_external_method,NULL);
|
||||
runtime_create_method_on_object(wpad,"buttonsup",rt,NULL,__wpad_buttonsup_external_method,NULL);
|
||||
|
||||
runtime_create_number_on_object(wpad,"BUTTON_A",rt,WPAD_BUTTON_A);
|
||||
runtime_create_number_on_object(wpad,"BUTTON_B",rt,WPAD_BUTTON_B);
|
||||
runtime_create_number_on_object(wpad,"BUTTON_1",rt,WPAD_BUTTON_1);
|
||||
runtime_create_number_on_object(wpad,"BUTTON_2",rt,WPAD_BUTTON_2);
|
||||
runtime_create_number_on_object(wpad,"BUTTON_HOME",rt,WPAD_BUTTON_HOME);
|
||||
runtime_create_number_on_object(wpad,"BUTTON_UP",rt,WPAD_BUTTON_UP);
|
||||
runtime_create_number_on_object(wpad,"BUTTON_DOWN",rt,WPAD_BUTTON_DOWN);
|
||||
runtime_create_number_on_object(wpad,"BUTTON_LEFT",rt,WPAD_BUTTON_LEFT);
|
||||
runtime_create_number_on_object(wpad,"BUTTON_RIGHT",rt,WPAD_BUTTON_RIGHT);
|
||||
runtime_create_number_on_object(wpad,"BUTTON_PLUS",rt,WPAD_BUTTON_PLUS);
|
||||
runtime_create_number_on_object(wpad,"BUTTON_MINUS",rt,WPAD_BUTTON_MINUS);
|
||||
}
|
||||
//dict_setkvp(wpad->data.dict,);
|
||||
rt->globals->setvariable(rt->globals,"wpad",wpad);
|
||||
|
|
|
@ -8,7 +8,7 @@ tlang_c_object_files := $(patsubst src/%.c, build/%.o, $(tlang_c_source_files))
|
|||
|
||||
|
||||
$(target): $(tlang_c_object_files)
|
||||
$(CC) -o $(target) $(CFLAGS) -L../libtlang $(tlang_c_object_files) -ltlang -lpthread -lSDL2 -lSDL2_gfx -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lm
|
||||
$(CC) -o $(target) $(CFLAGS) -L../libtlang $(tlang_c_object_files) -ltlang -lpthread -lSDL2 -lSDL2_gfx -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lmbedtls -lmbedx509 -lmbedcrypto -lpng -ljpeg -lm
|
||||
|
||||
$(tlang_c_object_files): build/%.o : src/%.c
|
||||
mkdir -p $(dir $@) && \
|
||||
|
|
|
@ -8,7 +8,9 @@ void register_funcs(runtime_t* rt)
|
|||
int main(int argc,char** argv)
|
||||
{
|
||||
runtime_t* rt = runtime_init();
|
||||
runtime_register_std(rt);
|
||||
runtime_register(rt,register_funcs);
|
||||
|
||||
if(argc < 2)
|
||||
{
|
||||
string_t* cmd=string_create();
|
||||
|
|
|
@ -3,6 +3,11 @@ build:
|
|||
|
||||
build-tlang-external:
|
||||
tlang src/wrappergen.tlang src/data.txt dest --external
|
||||
sdl:
|
||||
tlang src/wrappergen.tlang src/sdl.txt wrappers --omit
|
||||
PHONY: install
|
||||
install: sdl
|
||||
cp wrappers/sdl.c ../libtlang/src/sdl2.c ; true
|
||||
|
||||
PHONY: clean
|
||||
clean:
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#!/usr/local/bin/tlang
|
||||
__internal_tlang ="\"";
|
||||
__internal_tlang2 ="\"";
|
||||
//valid identifiers for function args: char, bool, number, string, null
|
||||
__tlang_header = "#include \"tlang.h\"\n"
|
||||
//valid identifiers for function args: char, bool, number, string, null, ptr
|
||||
//numbers are used for pointers
|
||||
//if a function requires list (array in language), dict, null or undefined implement those functions yourself
|
||||
|
||||
|
@ -151,7 +150,11 @@ func generateFuncCall(tlangRet,fName,argCount)
|
|||
}else if(tlangRet == "number")
|
||||
{
|
||||
res = "double _res = (double)";
|
||||
}else if(tlangRet == "bool")
|
||||
}else if(tlangRet == "ptr")
|
||||
{
|
||||
res = "double _res = (double)(uintptr_t)(void*)";
|
||||
}
|
||||
else if(tlangRet == "bool")
|
||||
{
|
||||
res = "bool _res = (bool)";
|
||||
}else if(tlangRet == "char")
|
||||
|
@ -180,7 +183,7 @@ func generateReturn(tlang)
|
|||
}else if(tlang == "string")
|
||||
{
|
||||
ret="string_t* _ress=string_create();\nstring_appendp(_ress,_res);\nfree(_res);\nreturn tobject_string(rt,_ress);";
|
||||
}else if(tlang == "number")
|
||||
}else if(tlang == "number" || tlang == "ptr")
|
||||
{
|
||||
ret = "return tobject_number(rt,_res);";
|
||||
}else if(tlang == "bool")
|
||||
|
@ -210,6 +213,11 @@ func generateArg(c,tlang,num)
|
|||
//TYPE* _argN = (TYPE*)string_dupp(args->items[N]->data.string);
|
||||
res += " _arg" + num + " = (" + c + ")string_dupp(args->items[" + num + "]->data.string);"
|
||||
}
|
||||
if(tlang == "ptr")
|
||||
{
|
||||
//TYPE* _argN = (TYPE*)string_dupp(args->items[N]->data.string);
|
||||
res += " _arg" + num + " = (" + c + ")(void*)(uintptr_t)args->items[" + num + "]->data.number;";
|
||||
}
|
||||
else if(tlang == "number")
|
||||
{
|
||||
res += " _arg" + num + " = (" + c + ")args->items[" + num + "]->data.number;";
|
||||
|
@ -263,9 +271,9 @@ func generateFuncBody(parse,name)
|
|||
if(tS == "string" || tS == "string_nofree")
|
||||
{
|
||||
t = "tstring";
|
||||
}else if(tS == "number")
|
||||
}else if(tS == "number" || tS == "ptr")
|
||||
{
|
||||
t = "tnumber";
|
||||
t = "ptr";
|
||||
}else if(tS == "char")
|
||||
{
|
||||
t = "tchar";
|
||||
|
@ -274,7 +282,14 @@ func generateFuncBody(parse,name)
|
|||
{
|
||||
t = "tbool";
|
||||
}
|
||||
str += " && args->items[" + i + "]->type == " + t;
|
||||
if(t == "ptr")
|
||||
{
|
||||
|
||||
str += " && (args->items[" + i + "]->type == tnumber || args->items[" + i + "]->type == tnull)";
|
||||
}else{
|
||||
str += " && args->items[" + i + "]->type == " + t;
|
||||
}
|
||||
|
||||
}
|
||||
str += ")\n{\n";
|
||||
|
||||
|
@ -346,8 +361,11 @@ func main(src,destDir,$internal_tlang)
|
|||
}
|
||||
if(internal_tlang == "--external")
|
||||
{
|
||||
__internal_tlang = "<";
|
||||
__internal_tlang2 = ">";
|
||||
__tlang_header = "#include <tlang.h>\n";
|
||||
}
|
||||
if(internal_tlang == "--omit")
|
||||
{
|
||||
__tlang_header = "";
|
||||
}
|
||||
ls = create.array();
|
||||
lines=fs.readalltext(src);
|
||||
|
@ -376,6 +394,24 @@ func main(src,destDir,$internal_tlang)
|
|||
mls=getLs(wrappers,curName);
|
||||
mls.includes += "#include \"" + j[1] + "\"\n";
|
||||
}
|
||||
else if(j[0] == "INCLUDE_NOW")
|
||||
{
|
||||
mls=getLs(wrappers,curName);
|
||||
mls.includes += fs.readalltext(j[1]);
|
||||
}
|
||||
else if(j[0] == "EXEC_FUNC")
|
||||
{
|
||||
mls=getLs(wrappers,curName);
|
||||
mls.calls += j[1] + "(rt,_" + curName + ");\n";
|
||||
}
|
||||
else if(j[0] == "ADD_FUNC")
|
||||
{
|
||||
mls=getLs(wrappers,curName);
|
||||
eS = create.dict();
|
||||
eS.left = create.dict();
|
||||
eS.left.name = j[1];
|
||||
mls.calls += runtime_on_dict_name(eS,curName) + "\n";
|
||||
}
|
||||
else if(j[0] == "FUNCTION")
|
||||
{
|
||||
mls=getLs(wrappers,curName);
|
||||
|
@ -424,9 +460,10 @@ func main(src,destDir,$internal_tlang)
|
|||
{
|
||||
file = fs.combine(destDir,item.name + ".c");
|
||||
console.writeln(file);
|
||||
file_con = "#include " + __internal_tlang + "tlang.h" + __internal_tlang2 + "\n" + item.includes + "\n" +
|
||||
|
||||
file_con = __tlang_header + item.includes + "\n" +
|
||||
item.funcs + "\nvoid runtime_register_" + item.name +
|
||||
"(runtime_t* rt)\n{\n_" + item.name + " = tobject_create(rt);\n_" +
|
||||
"(runtime_t* rt)\n{\ntobject_t* _" + item.name + " = tobject_create(rt);\n_" +
|
||||
item.name + "->type = tdict;\n_" + item.name + "->data.dict = dict_create();\n" + item.calls +
|
||||
"\nrt->globals->setvariable(rt->globals,\"" + item.name + "\",_" + item.name + ");\n}\n";
|
||||
|
||||
|
|
Loading…
Reference in New Issue