Skip to content

Commit 0cbe0dc

Browse files
authored
Fix example lua (#463)
1 parent 681876c commit 0cbe0dc

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

examples/lua/main.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,20 @@ int main(int argc, char** argv)
4343

4444
std::string new_package_path = s["package"]["path"];
4545

46-
sol::function function = s.script_file("scripts/example.lua");
47-
48-
do
46+
try
47+
{
48+
sol::table module_example = s.load_file("scripts/example.lua").call();
49+
sol::function update_func = module_example["update"];
50+
do
51+
{
52+
std::this_thread::sleep_for(std::chrono::milliseconds(16));
53+
} while (!update_func(50.0 / 1000));
54+
}
55+
catch (const sol::error& e)
4956
{
50-
std::this_thread::sleep_for(std::chrono::milliseconds(16));
51-
} while (!function.call(50.0 / 1000));
57+
std::cerr << "Error: " << e.what() << std::endl;
58+
return -1;
59+
}
5260
#else
5361
kaguya::State s;
5462
s.openlibs();
@@ -65,11 +73,12 @@ int main(int argc, char** argv)
6573
s["package"]["path"] = package_path;
6674

6775
auto function = s.loadfile("scripts/example.lua");
68-
auto update = function();
76+
auto module_example = function();
77+
auto update_func = module_example["update"];
6978
do
7079
{
7180
std::this_thread::sleep_for(std::chrono::milliseconds(50));
72-
} while (!update(50.0 / 1000));
81+
} while (!update_func(50.0 / 1000));
7382
#endif
7483
return 0;
7584
}

yasio/bindings/lyasio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ end
795795

796796
char version[32];
797797
snprintf(version, sizeof(version), "%x.%x.%x", (YASIO_VERSION_NUM >> 16) & 0xff, (YASIO_VERSION_NUM >> 8) & 0xff, YASIO_VERSION_NUM & 0xff);
798-
YASIO_EXPORT_ANY(version);
798+
yasio_lib["version"] = std::string(version);
799799

800800
return yasio_lib.push(); /* return 'yasio' table */
801801
}

0 commit comments

Comments
 (0)