Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added proof of concept for module imports #99

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dome.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Dome Configuration
[imports]
code = example/
code/ = example/
9 changes: 9 additions & 0 deletions example/code.wren
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

import "code/code2" for Code2

class Code {
static init() {
System.print("Code 1 Called")
Code2.init()
}
}
6 changes: 6 additions & 0 deletions example/code2.wren
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

class Code2 {
static init() {
System.print("Code 2 Called")
}
}
6 changes: 5 additions & 1 deletion main.wren
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import "graphics" for Canvas, Color
import "code" for Code

class Game {
static init() {}
static init() {
Code.init()
}
static update() {}
static draw(dt) {
Canvas.print("DOME Installed Successfully.", 10, 10, Color.white)
Expand Down
50 changes: 50 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <ini/ini.h>
#include <ini/ini.c>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "config.h"


static int CONFIG_handler(void* config, const char* section, const char* name,
const char* value) {

CONFIG_STORAGE * pconfig = (CONFIG_STORAGE *) config;

if (pconfig->count > CONFIG_MAX_ITEMS) {
return -1;
}

CONFIG_VALUE item;
item.section = strdup(section);
item.name = strdup(name);
item.value = strdup(value);

pconfig->items[pconfig->count] = item;
pconfig->count++;

return 0;
}

CONFIG_STORAGE CONFIG_readFile(char * string) {
CONFIG_STORAGE config;
config.count = 0;

ini_parse_string(string, CONFIG_handler, &config);
return config;
}

char * CONFIG_readValue(void* config, char * section, char * name) {
CONFIG_STORAGE * pconfig = (CONFIG_STORAGE *) config;
CONFIG_VALUE item;

for(int i = 0; i < pconfig->count; i++) {
item = pconfig->items[i];
if (strcmp(item.section, section) == 0 && strcmp(item.name, name) == 0) {
return item.value;
}
}
return NULL;
}
18 changes: 18 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#ifndef CONFIG_H_INCLUDED
#define CONFIG_H_INCLUDED

#define CONFIG_MAX_ITEMS 255

typedef struct {
const char * section;
const char * name;
const char * value;
} CONFIG_VALUE;

typedef struct {
int count;
CONFIG_VALUE items[CONFIG_MAX_ITEMS];
} CONFIG_STORAGE;

#endif
3 changes: 2 additions & 1 deletion src/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ ENGINE_readFile(ENGINE* engine, char* path, size_t* lengthPtr) {
strcat(pathBuf, path);
}

ENGINE_printLog(engine, "Reading from filesystem: %s\n", pathBuf);

if (!doesFileExist(pathBuf)) {
return NULL;
}

ENGINE_printLog(engine, "Reading from filesystem: %s\n", pathBuf);
return readEntireFile(pathBuf, lengthPtr);
}

Expand Down
3 changes: 3 additions & 0 deletions src/engine.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "config.h"

// Forward-declaring some methods for interacting with the AudioEngine
// for managing memory and initialization
struct AUDIO_ENGINE_t;
Expand Down Expand Up @@ -50,6 +52,7 @@ typedef struct {
bool debugEnabled;
bool vsyncEnabled;
ENGINE_DEBUG debug;
CONFIG_STORAGE config;
} ENGINE;


Expand Down
Loading