Skip to content

Commit 2df6474

Browse files
committed
fix uri error
1 parent f309e72 commit 2df6474

6 files changed

Lines changed: 44 additions & 35 deletions

File tree

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ compile_commands.json
77
vsxmake*/
88
.idea/
99
.DS_Store
10-
11-
10+
cmake*/
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
#include "da_script_bind.h"
22
#include "da_script_engine.hpp"
3+
#include <cstdio>
34

4-
5-
extern "C" {
6-
DaScriptVm* DaScriptEngineCreate(void)
5+
extern "C"
76
{
8-
return reinterpret_cast<DaScriptVm*>(new DaScriptEngine());
9-
}
7+
DaScriptVm *DaScriptEngineCreate(void)
8+
{
9+
return (DaScriptVm *)(new DaScriptEngine());
10+
}
1011

11-
void DaScriptEngineDestroy(DaScriptVm* self)
12-
{
13-
delete reinterpret_cast<DaScriptEngine*>(self);
14-
}
12+
void DaScriptEngineDestroy(DaScriptVm *self)
13+
{
14+
delete reinterpret_cast<DaScriptEngine *>(self);
15+
}
1516

16-
bool DaScriptEngineCompileScript(DaScriptVm* self, const char* script_name)
17-
{
18-
return reinterpret_cast<DaScriptEngine*>(self)->CompileScript(script_name);
19-
}
17+
bool DaScriptEngineCompileScript(DaScriptVm *self, const char *script_name)
18+
{
19+
return reinterpret_cast<DaScriptEngine *>(self)->CompileScript(script_name);
20+
}
2021

21-
bool DaScriptEngineRunScript(DaScriptVm* self, const char* script_name, const char* entry)
22-
{
23-
return reinterpret_cast<DaScriptEngine*>(self)->RunScript(script_name, entry);
24-
}
22+
bool DaScriptEngineRunScript(DaScriptVm *self, const char *script_name, const char *entry)
23+
{
24+
return reinterpret_cast<DaScriptEngine *>(self)->RunScript(script_name, entry);
25+
}
2526
} // extern "C"

grngame/bindings/da_script_engine.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "daScript/ast/dyn_modules.h"
33
#include "grngame/dev/logging.h"
44
#include "grngame/platform/directories.h"
5-
5+
#include <cstdio>
66

77
DaScriptEngine::DaScriptEngine() : file_access(das::make_smart<das::FsFileAccess>())
88
{
@@ -18,31 +18,39 @@ DaScriptEngine::~DaScriptEngine()
1818
das::Module::Shutdown();
1919
}
2020

21-
bool DaScriptEngine::CompileScript(const char* script_name)
21+
bool DaScriptEngine::CompileScript(const char *script_name)
2222
{
23-
main_program = das::compileDaScript(script_name, file_access, text_printer, module_group, policies);
24-
if (main_program->failed())
23+
auto program = das::compileDaScript(script_name, file_access, text_printer, module_group, policies);
24+
if (program->failed())
2525
{
2626
LOG_ERROR("Failed to compile daScript file '%s':\n", script_name);
27-
LogErrorsOfProgram(main_program);
27+
LogErrorsOfProgram(program);
2828
return false;
2929
}
3030

31-
main_context = new das::Context(main_program->getContextStackSize());
31+
contexts[script_name] = das::make_smart<das::Context>(program->getContextStackSize());
3232

33-
if (!main_program->simulate(*main_context, text_printer))
33+
if (!program->simulate(*contexts[script_name], text_printer))
3434
{
3535
LOG_ERROR("Failed to simulate script '%s':\n", script_name);
36-
LogErrorsOfProgram(main_program);
36+
LogErrorsOfProgram(program);
3737
return false;
3838
}
3939

4040
return true;
4141
}
4242

43-
bool DaScriptEngine::RunScript(const char* script_name, const char* entry)
43+
bool DaScriptEngine::RunScript(const char *script_name, const char *entry)
4444
{
45-
auto functions = main_context->findFunctions(entry);
45+
auto it = contexts.find(script_name);
46+
if (it == contexts.end())
47+
{
48+
LOG_ERROR("No such script '%s'\n", script_name);
49+
return false;
50+
}
51+
52+
auto functions = it->second->findFunctions(entry);
53+
4654
if (functions.empty())
4755
{
4856
LOG_ERROR("Failed to find function '%s' in script '%s'", entry, script_name);
@@ -55,14 +63,14 @@ bool DaScriptEngine::RunScript(const char* script_name, const char* entry)
5563
}
5664
else
5765
{
58-
main_context->evalWithCatch(functions.at(0), nullptr);
66+
contexts[script_name]->evalWithCatch(functions.at(0), nullptr);
5967
return true;
6068
}
6169
}
6270

63-
void DaScriptEngine::LogErrorsOfProgram(const das::ProgramPtr& program)
71+
void DaScriptEngine::LogErrorsOfProgram(const das::ProgramPtr &program)
6472
{
65-
for (const auto& err : program->errors)
73+
for (const auto &err : program->errors)
6674
{
6775
LOG_ERROR("- %s\n", err.what.c_str()); // TODO better logging
6876
}

grngame/bindings/da_script_engine.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
2+
#include <unordered_map>
23
#define DAS_SMART_PTR_TRACKER 0
34
#define DAS_SMART_PTR_MAGIC 0
45
#include <daScript/daScript.h>
@@ -10,8 +11,7 @@ class DaScriptEngine
1011
das::TextPrinter text_printer;
1112
das::ModuleGroup module_group;
1213
das::CodeOfPolicies policies;
13-
das::ProgramPtr main_program;
14-
das::Context* main_context;
14+
std::unordered_map<std::string, das::smart_ptr<das::Context>> contexts;
1515
public:
1616
DaScriptEngine();
1717
~DaScriptEngine();

grngame/core/app.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void EngineStart(AppInfo* app_info)
7979
if (!DaScriptEngineCompileScript(g_app.da_script_engine, "hello.das"))
8080
exit(7);
8181

82-
if (!DaScriptEngineRunScript(g_app.da_script_engine, "hellos.das", "main"))
82+
if (!DaScriptEngineRunScript(g_app.da_script_engine, "hello.das", "main"))
8383
exit(8);
8484

8585
MainLoop();

xmake.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ package("daslang")
3838
"-DDAS_GLFW_DISABLED=ON",
3939
"-DDAS_STDDLG_DISABLED=ON",
4040
"-DDAS_STBIMAGE_DISABLED=ON",
41+
"-DDAS_URIPARSER_DISABLED=ON",
4142
"-DDAS_STBTRUETYPE_DISABLED=ON",
4243
}
4344

0 commit comments

Comments
 (0)