Ruby embedded

This commit is contained in:
John Alanbrook 2022-08-01 18:32:58 +00:00
parent 760765d350
commit 2e7da5c4e6
4 changed files with 33 additions and 57 deletions

View file

@ -12,7 +12,8 @@ UNAME_P != uname -m
CCACHE = #ccache CCACHE = #ccache
#CC specifies which compiler we're using #CC specifies which compiler we're using
CC = $(CCACHE) tcc -DSDL_DISABLE_IMMINTRIN_H CC = $(CCACHE) clang -DSDL_DISABLE_IMMINTRIN_H
CLINK = clang
MUSL = /usr/local/musl/include MUSL = /usr/local/musl/include
@ -96,8 +97,8 @@ ifeq ($(UNAME), Windows_NT)
CLIBS = glew32 CLIBS = glew32
EXT = .exe EXT = .exe
else else
LINKER_FLAGS = -g /usr/lib64/pipewire-0.3/jack/libjack.so.0 #/usr/local/lib/tcc/bcheck.o /usr/local/lib/tcc/bt-exe.o /usr/local/lib/tcc/bt-log.o LINKER_FLAGS = -g /usr/lib64/pipewire-0.3/jack/libjack.so.0
ELIBS = m c engine editor glfw3 portaudio rt asound pthread SDL2 yughc ELIBS = m c engine editor glfw3 portaudio rt asound pthread SDL2 yughc mruby
CLIBS = CLIBS =
EXT = EXT =
endif endif
@ -122,12 +123,12 @@ LINK = $(LIBPATH) $(LINKER_FLAGS) $(LELIBS) -o $@
engine: tags $(yuginec:.%.c=$(objprefix)%.o) $(ENGINE) engine: tags $(yuginec:.%.c=$(objprefix)%.o) $(ENGINE)
@echo Linking engine @echo Linking engine
@$(CC) $@ $(LINK) @$(CLINK) $@ $(LINK)
@echo Finished build @echo Finished build
editor: tags $(yuginec:.%.c=$(objprefix)%.o) $(EDITOR) $(ENGINE) editor: tags $(yuginec:.%.c=$(objprefix)%.o) $(EDITOR) $(ENGINE)
@echo Linking editor @echo Linking editor
@$(CC) $^ $(LINK) @$(CLINK) $^ $(LINK)
@echo Finished build @echo Finished build
$(ENGINE): $(eobjects) bin/libglfw3.a $(ENGINE): $(eobjects) bin/libglfw3.a
@ -142,12 +143,12 @@ $(EDITOR): $(edobjects)
xbrainstorm: $(bsobjects) $(ENGINE) $(EDITOR) xbrainstorm: $(bsobjects) $(ENGINE) $(EDITOR)
@echo Making brainstorm @echo Making brainstorm
$(CC) $^ $(LINK) $(CLINK) $^ $(LINK)
@mv xbrainstorm brainstorm/brainstorm$(EXT) @mv xbrainstorm brainstorm/brainstorm$(EXT)
pinball: tags $(ENGINE) $(pinobjects) pinball: tags $(ENGINE) $(pinobjects)
@echo Making pinball @echo Making pinball
@$(CC) $(pinobjects) $(LINK) -o $@ @$(CLINK) $(pinobjects) $(LINK) -o $@
@mv pinball paladin/pinball @mv pinball paladin/pinball
bin/libglfw3.a: bin/libglfw3.a:

View file

@ -8,6 +8,8 @@
#include "circbuf.h" #include "circbuf.h"
struct dsp_iir;
void dsp_rectify(short *in, short *out, int n); void dsp_rectify(short *in, short *out, int n);

View file

@ -1,59 +1,34 @@
#include "script.h" #include "script.h"
#include "gameobject.h" #include "stdio.h"
#include "mruby.h"
#include "mruby/compile.h"
/*#include <s7.h> static mrb_state *mrb;
s7_scheme *s7 = NULL; int fib(int n) {
if (n < 2) return n;
s7_pointer s7square(s7_scheme * sc, s7_pointer args) return fib(n-1) + fib(n-2);
{
if (s7_is_integer(s7_car(args)))
return (s7_make_integer
(sc, s7_integer(s7_car(args)) * s7_integer(s7_car(args))));
return (s7_wrong_type_arg_error
(sc, "square", 1, s7_car(args), "an integer"));
} }
s7_pointer s7move(s7_scheme * sc, s7_pointer args) mrb_value mrb_fib(mrb_state *mrb, mrb_value self) {
{ int n;
if (s7_is_number(s7_car(args)) && s7_is_number(s7_cadr(args))) { mrb_get_args(mrb, "i", &n);
gameobject_move(updateGO, s7_real(s7_car(args)), return mrb_fixnum_value(fib(n));
s7_real(s7_cadr(args)));
return args;
}
return args;
} }
s7_pointer s7rotate(s7_scheme * sc, s7_pointer args) void script_init() {
{ mrb = mrb_open();
if (s7_is_number(s7_car(args))) { mrb_define_method(mrb, mrb->object_class, "fib", mrb_fib, MRB_ARGS_REQ(1));
gameobject_rotate(updateGO, s7_real(s7_car(args)));
return (s7_make_real(sc, cpBodyGetAngle(updateGO->body)));
}
return (s7_wrong_type_arg_error
(sc, "rotate", 1, s7_car(args), "a number"));
}
*/
void script_init()
{
/*
s7 = s7_init();
s7_define_function(s7, "square", s7square, 1, 0, 0,
"(square int) squares int");
s7_define_function(s7, "move", s7move, 1, 0, 0,
"(move (xs ys)) moves at xs and ys pixels per second");
s7_define_function(s7, "rotate", s7rotate, 1, 0, 0,
"(rotate ms) rotates at ms meters per second");
*/
} }
void script_run(const char *script) void script_run(const char *script) {
{ mrb_load_string(mrb, script);
//s7_eval_c_string(s7, script); }
void script_dofile(const char *file) {
FILE *mrbf = fopen(file, "r");
mrb_load_file(mrb, mrbf);
fclose(mrbf);
} }

View file

@ -1,10 +1,8 @@
#ifndef SCRIPT_H #ifndef SCRIPT_H
#define SCRIPT_H #define SCRIPT_H
struct s7_scheme;
extern struct s7_scheme *s7;
void script_init(); void script_init();
void script_run(const char *script); void script_run(const char *script);
void script_dofile(const char *file);
#endif #endif